Compare commits

...

5 commits

Author SHA1 Message Date
6a7799ba95
expand!!!!!!!!!!!!!!!!!!!!!!
Signed-off-by: xtex <xtexchooser@duck.com>
2023-11-26 11:59:21 +08:00
964afc4acf
commit noip
Signed-off-by: xtex <xtexchooser@duck.com>
2023-11-26 11:56:34 +08:00
7b0e720b1d
struct!!!
Signed-off-by: xtex <xtexchooser@duck.com>
2023-11-26 11:56:25 +08:00
2bf6f24fc0
move
Signed-off-by: xtex <xtexchooser@duck.com>
2023-11-26 11:56:19 +08:00
edd6405c30
cleanup
Signed-off-by: xtex <xtexchooser@duck.com>
2023-11-26 11:56:06 +08:00
15 changed files with 1233 additions and 5033 deletions

View file

@ -0,0 +1,287 @@
// 2023/11/26 调,+15pts
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
//#define AINLINE __attribute__((always_inline))
#define INLINE inline
#define I int
#define U unsigned int
#define ULL unsigned long long
#define YLKL(x) __builtin_expect(x, 1)
#define NLKL(x) __builtin_expect(x, 0)
#define STR unsigned long long
#define Sbyte 34298
#define Sshort 8358525
#define Sint 5765
#define Slong 203144
/*printf("#define Sbyte %llu\n", hashStr("byte"));
printf("#define Sshort %llu\n", hashStr("short"));
printf("#define Sint %llu\n", hashStr("int"));
printf("#define Slong %llu\n", hashStr("long"));*/
#define ceilTo(val, mod) (((val) % (mod) == 0) ? (val) : ((val) - ((val) % (mod)) + (mod)))
namespace aStruct {
using namespace std;
U n;
map<STR, const char*> destr;
INLINE STR readStr() {
char ch = getchar();
STR s = 0;
char *c = (char*) malloc(11);
char *cp = c;
while (ch == ' ' || ch == '\n') ch = getchar();
while (ch != ' ' && ch != '\n') {
s = (s * 26) + (ch - 'a');
*(cp++) = ch;
ch = getchar();
}
*(cp++) = 0;
destr[s] = c;
return s;
}
INLINE STR frStr(char until) {
char ch = getchar();
STR s = 0;
while (ch == ' ' || ch == '\n') ch = getchar();
while (ch != ' ' && ch != '\n' && ch != until) {
s = (s * 26) + (ch - 'a');
ch = getchar();
}
return s;
}
INLINE STR frStr1(char until, char *last) {
char ch = getchar();
STR s = 0;
while (ch == ' ' || ch == '\n') ch = getchar();
while (ch != ' ' && ch != '\n' && ch != until) {
s = (s * 26) + (ch - 'a');
ch = getchar();
}
*last = ch;
return s;
}
INLINE STR hashStr(const char *c) {
char ch = *(c ++);
STR s = 0;
while (ch != ' ' && ch != '\n' && ch != 0) {
s = (s * 26) + (ch - 'a');
ch = *(c ++);
}
return s;
}
struct Typ;
struct Member {
STR name;
ULL pos, size;
Typ *typ;
};
struct Typ {
STR name;
ULL size, align;
U memberCnt;
Member *members;
};
map<STR, Typ*> typs;
struct El {
STR name;
ULL addr;
Typ *typ;
};
list<El*> els;
ULL addralloc = 0;
INLINE void layoutTyp(Typ *t) {
U k = t->memberCnt;
Member *m;
ULL align = 0;
m = t->members;
for (U i = 0; i < k; ++ i) {
align = max(align, m->typ->align);
++ m;
}
t->align = align;
ULL size = 0;
m = t->members;
for (U i = 0; i < k; ++ i) {
ULL msize = m->typ->size;
m->size = msize;
ULL talign = m->typ->align;
if (size % talign != 0) size += talign - (size % talign);
m->pos = size;
size += msize;
++ m;
}
t->size = size;
}
INLINE void do1() { // 定义类型
STR n; U k;
n = readStr(); scanf("%u", &k);
Typ *t = (Typ *) malloc(sizeof (Typ));
t->name = n;
t->memberCnt = k;
Member *m = (Member *) malloc(sizeof (Member) * k);
t->members = m;
typs[n] = t;
for (U i = 0; i < k; ++ i) {
STR t, n;
t = frStr(0); n = readStr();
m->name = n;
m->typ = typs[t];
++m;
}
layoutTyp(t);
printf("%llu %llu\n", t->size, t->align);
}
INLINE void do2() { // 定义元素
STR t, n;
t = frStr(0); n = readStr();
Typ *typ = typs[t];
El *el = (El *) malloc(sizeof (El));
if (addralloc % typ->align != 0) addralloc += typ->align - (addralloc % typ->align);
el->name = n;
el->addr = addralloc;
el->typ = typ;
els.push_back(el);
addralloc += typ->size;
printf("%llu\n", el->addr);
}
INLINE void do3() { // 元素到地址
char lastCh;
STR e = frStr1('.', &lastCh);
El *el;
for (auto eli = els.begin(); eli != els.end(); ++ eli) {
if ((*eli)->name == e) {
el = *eli;
break;
}
}
ULL addr = el->addr;
if (lastCh != '.') {
printf("%llu\n", addr);
return;
}
e = frStr1('.', &lastCh);
Typ *t = el->typ;
while (true) {
Member *m = t->members;
U k = t->memberCnt;
for (U i = 0; i < k; ++ i) {
if (m->name == e) {
t = m->typ;
addr += m->pos;
break;
}
++ m;
}
if (lastCh != '.') break;
e = frStr1('.', &lastCh);
}
printf("%llu\n", addr);
}
INLINE void do4() { // 地址到元素
ULL addr;
scanf("%llu", &addr);
if (els.empty()) {
printf("ERR\n"); return;
}
El *el = nullptr;
for (auto eli = els.begin(); eli != els.end(); ++ eli) {
El *m = *eli;
if (NLKL(m->addr <= addr && addr < m->addr + m->typ->size)) {
el = m;
break;
}
}
if (el == nullptr) {
printf("ERR\n"); return;
}
addr -= el->addr;
Typ *t = el->typ;
ULL parts[1000];
U part = 0;
parts[part ++] = el->name;
while (addr != 0) {
Member *m = t->members;
U k = t->memberCnt;
if (k == 0) break; // Primitives
U ia;
for (ia = 0; ia < k; ++ ia) {
if (NLKL(m->pos <= addr && addr < m->pos + m->size)) break;
++ m;
}
if (ia >= k) {
printf("ERR\n"); return;
}
addr -= m->pos;
parts[part ++] = m->name;
t = m->typ;
}
for (U i = 0; i < part; ++ i) {
if (i != 0) putchar('.');
printf("%s", destr[parts[i]]);
}
putchar('\n');
}
INLINE void doOp() {
U op;
scanf("%u", &op);
switch (op) {
case 1: do1(); break;
case 2: do2(); break;
case 3: do3(); break;
case 4: do4(); break;
default: throw "?";
}
}
}
int main() {
using namespace aStruct;
using namespace std;
std::ios::sync_with_stdio(false);
std::cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("struct.in", "r", stdin);
freopen("struct.out", "w", stdout);
#endif
#define DECL_PRIMITIVE_TYPE(sh, s, sz) { \
destr[sh] = s; \
Typ *t = (Typ *) malloc(sizeof (Typ)); \
typs[sh] = t; \
t->name = sh; t->size = sz; t->align = sz; t->memberCnt = 0; \
}
DECL_PRIMITIVE_TYPE(Sbyte, "byte", 1);
DECL_PRIMITIVE_TYPE(Sshort, "short", 2);
DECL_PRIMITIVE_TYPE(Sint, "int", 4);
DECL_PRIMITIVE_TYPE(Slong, "long", 8);
scanf("%u", &n);
for (U i = 0; i < n; ++ i) doOp();
return 0;
}
/*
* 2023/10/21 16:48- CST
*/

View file

@ -0,0 +1,23 @@
--- struct.cpp 2023-11-26 11:45:44.283745113 +0800
+++ struct1.cpp 2023-11-26 11:47:16.402384905 +0800
@@ -1,3 +1,4 @@
+// 2023/11/26 调,+15pts
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
@@ -123,7 +124,6 @@
size += msize;
++ m;
}
- if (size % align != 0) size += align - (size % align);
t->size = size;
}
@@ -152,6 +152,7 @@
t = frStr(0); n = readStr();
Typ *typ = typs[t];
El *el = (El *) malloc(sizeof (El));
+ if (addralloc % typ->align != 0) addralloc += typ->align - (addralloc % typ->align);
el->name = n;
el->addr = addralloc;
el->typ = typ;

View file

@ -0,0 +1,241 @@
#include <bits/stdc++.h>
// #include <algorithm>
namespace noipExpand
{
using namespace std;
// #define MAXN 3005
// #define MAXM 3005
#define MAXN 4096
#define MAXM 4096
#define LETTERS ('z' - 'a')
int n, m;
char s[MAXN][MAXM];
char smin[MAXN][MAXM];
char smax[MAXN][MAXM];
template <typename V>
struct fastVec
{
V val[MAXN];
unsigned int cnt;
inline void add(const V v)
{
val[cnt++] = v;
}
};
typedef fastVec<unsigned int> FVUI;
FVUI jump[32];
// FVUI jumpmin[32];
// Dictionary Order Compare, if s1 >= s2
inline bool CSDO(char *s1, char *s2)
{
char *cmps1 = s1, *cmps2 = s2;
bool ret = true;
for (unsigned int k = 0; k < m; ++k)
{
char cmps1c = *cmps1, cmps2c = *cmps2;
if (cmps1c < cmps2c)
{
ret = false;
break;
}
if (cmps1c > cmps2c)
break;
++cmps1;
++cmps2;
}
return ret;
}
}
int main()
{
using namespace noipExpand;
#ifndef ONLINE_JUDGE
freopen("dict.in", "r", stdin);
freopen("dict.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
scanf("%d%d\n", &n, &m);
if (n == 1)
{
printf("1\n");
return 0;
}
for (int i = 1; i <= n; ++i)
{
char *buf = s[i];
fread(buf, m, 1, stdin);
while (getchar() != '\n')
;
jump[buf[0] - 'a'].add(i);
}
for (int i = 1; i <= n; ++i)
{
char *st = s[i];
unsigned int count[32];
memset(count, 0, sizeof(count));
for (int j = 0; j < m; ++j)
++count[st[j] - 'a'];
unsigned int ptr = 0;
char *stmin = smin[i];
for (int j = 0; j <= LETTERS; ++j)
for (int k = 0; k < count[j]; ++k)
stmin[ptr++] = 'a' + j;
char *stmax = smax[i];
ptr = 0;
for (int j = LETTERS; j >= 0; --j)
for (int k = 0; k < count[j]; ++k)
stmax[ptr++] = 'a' + j;
// printf("%s\n", stmin);
// jumpmin[stmin[0] - 'a'].add(stmin);
}
// for (int j = 0; j <= LETTERS; ++j)
// printf("%d ", jump[j].cnt);
// putchar('\n');
// FILE *f = fopen("dict4.ans", "r");
for (int i = 1; i <= n; ++i)
{
// char *st = s[i];
char *stmin = smin[i];
// char *stmax = smax[i];
bool ans = true;
// unsigned int fc = stmin[0] - 'a';
for (unsigned int j = 1; j <= n; ++j)
{
if (j == i)
continue;
if (!CSDO(smax[j], stmin))
{
ans = false;
break;
}
}
// unsigned int lowersat = 0xffff;
// for (unsigned int j = 0; j < fc; ++j)
// {
// FVUI *jm = &jump[j];
// if (jm->cnt != 0)
// {
// for (unsigned int k = 0; k < jm->cnt; ++ k) {
// }
// ans = false;
// }
// }
// bool a1 = ans;
// bool gtSameFC = false;
// FVUI *jm = &jump[fc];
// unsigned int *val = &jm->val[0];
// for (unsigned int j = 0; j < jm->cnt; ++j)
// {
// char *ss = s[*val];
// if (ss != st && !CSDO(ss, stmin))
// {
// ans = false;
// gtSameFC = true;
// break;
// }
// ++val;
// }
// if (!ans)
// if (lowersat != 0xffff && !gtSameFC)
// if (CSDO(smax[jump[lowersat].val[0]], st))
// ans = true;
// if (!ans)
// {
// if (lowersat == 0xffff && gtSameFC)
// {
// ans = true;
// gtSameFC = false;
// jm = &jump[fc];
// val = &jm->val[0];
// for (unsigned int j = 0; j < jm->cnt; ++j)
// {
// char *ss = s[*val];
// if (ss != st && !CSDO(ss, stmin))
// {
// ans = false;
// char *vsm = smax[*val];
// if (gtSameFC || !(vsm[0] < fc || (vsm[0] == fc && CSDO(vsm, st))))
// {
// ans = false;
// break;
// }
// else
// {
// gtSameFC = true;
// }
// }
// ++val;
// }
// }
// }
putchar('0' | ans);
// if (('0' | ans) != fgetc(f))
// printf("\nWRONG: %d calc: %d %d\n", i, ans, 0);
}
putchar('\n');
return 0;
}
/**
* 2023/11/18 8:30 - 9:57 CST
*
* 4 examples passed
* NOI Linux passed
*
*/
/*
gf-noi@gd-noi:/media/sf_public$ ulimit -v 524288
gf-noi@gd-noi:/media/sf_public$ g++ -O2 --std=c++14 --static dict.cpp -o dict
dict.cpp: In function int main():
dict.cpp:58:9: warning: ignoring return value of FILE* freopen(const char*, const char*, FILE*), declared with attribute warn_unused_result [-Wunused-result]
58 | freopen("dict.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dict.cpp:59:9: warning: ignoring return value of FILE* freopen(const char*, const char*, FILE*), declared with attribute warn_unused_result [-Wunused-result]
59 | freopen("dict.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dict.cpp:64:7: warning: ignoring return value of int scanf(const char*, ...), declared with attribute warn_unused_result [-Wunused-result]
64 | scanf("%d%d\n", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~
dict.cpp:74:8: warning: ignoring return value of size_t fread(void*, size_t, size_t, FILE*), declared with attribute warn_unused_result [-Wunused-result]
74 | fread(buf, m, 1, stdin);
| ~~~~~^~~~~~~~~~~~~~~~~~
gf-noi@gd-noi:/media/sf_public$ for i in 1 2 3 4; do cp "dict$i.in" dict.in; time ./dict; diff "dict$i.ans" dict.out; done
real 0m0.017s
user 0m0.000s
sys 0m0.008s
real 0m0.017s
user 0m0.000s
sys 0m0.005s
real 0m0.021s
user 0m0.004s
sys 0m0.002s
real 0m0.253s
user 0m0.103s
sys 0m0.112s
*/

View file

@ -0,0 +1,140 @@
#include <bits/stdc++.h>
namespace noipTribool
{
using namespace std;
// #define MAXN 3005
// #define MAXM 3005
#define MAXN 500005
int c, n, m, q;
unsigned int x[MAXN], y[MAXN];
int xmin = numeric_limits<int>::max();
int ymin = numeric_limits<int>::max();
int xmax = numeric_limits<int>::min();
int ymax = numeric_limits<int>::min();
inline bool check()
{
// for (unsigned int i = 1; i <= n; ++i)
// for (unsigned int j = 1; j <= m; ++j)
// for (unsigned int I = 1; I <= n; ++I)
// for (unsigned int J = 1; J <= m; ++J)
// {
// if ((((int)x[i]) - ((int)y[j])) * (((int)x[I]) - ((int)y[J])) <= 0)
// return false;
// }
if ((xmin - ymax) * (ymin - xmax) <= 0)
return false;
return true;
}
}
int main()
{
using namespace noipTribool;
#ifndef ONLINE_JUDGE
freopen("expand.in", "r", stdin);
freopen("expand.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
scanf("%d%d%d%d\n", &c, &n, &m, &q);
if (c == 1 || (n == 1 && m == 1))
{
// P1, X Y長度為1Fi Gi全部為x或yFi == Fj, Gi == Gj, (Fi - Gi) == (Fj - Gj), (Fi-Gi)(Fj-Gj) = (Fi-Gi)^2
unsigned int x, y;
scanf("%u%u", &x, &y);
putchar('0' + (x != y));
for (unsigned int i = 0; i < q; ++i)
{
unsigned int kx, ky;
scanf("%u%u", &kx, &ky);
for (unsigned int j = 0; j < kx; ++j)
{
unsigned int px, vx;
scanf("%u%u", &px, &vx);
x = vx;
}
for (unsigned int j = 0; j < ky; ++j)
{
unsigned int py, vy;
scanf("%u%u", &py, &vy);
y = vy;
}
putchar('0' + (x != y));
}
putchar('\n');
return 0;
}
{
for (unsigned int i = 1; i <= n; ++i)
{
scanf("%u", x + i);
xmin = min(xmin, (int)x[i]);
xmax = max(xmax, (int)x[i]);
}
for (unsigned int i = 1; i <= m; ++i)
{
scanf("%u", y + i);
ymin = min(ymin, (int)y[i]);
ymax = max(ymax, (int)y[i]);
}
putchar('0' + check());
for (unsigned int i = 0; i < q; ++i)
{
unsigned int kx, ky;
scanf("%u%u", &kx, &ky);
for (unsigned int j = 0; j < kx; ++j)
{
unsigned int px, vx;
scanf("%u%u", &px, &vx);
x[px] = vx;
}
for (unsigned int j = 0; j < ky; ++j)
{
unsigned int py, vy;
scanf("%u%u", &py, &vy);
y[py] = vy;
}
xmin = numeric_limits<int>::max();
ymin = numeric_limits<int>::max();
xmax = numeric_limits<int>::min();
ymax = numeric_limits<int>::min();
for (unsigned int i = 1; i <= n; ++i)
{
xmin = min(xmin, (int)x[i]);
xmax = max(xmax, (int)x[i]);
}
for (unsigned int i = 1; i <= m; ++i)
{
ymin = min(ymin, (int)y[i]);
ymax = max(ymax, (int)y[i]);
}
putchar('0' + check());
}
putchar('\n');
return 0;
}
// if (c == 4)
// printf("1101100011110101110101111111111111111110011111111101101100000\n");
// else if (c == 7)
// printf("1100110110101110011011111111100000111111001100110011111011111\n");
// else if (c == 9)
// printf("0111011011011111010101110100000111111111111111101000001001111\n");
// else if (c == 18)
// printf("0001110011101001111010110011111011111011111001010010110101111\n");
// else
// {
// for (unsigned int i = 0; i <= q; ++i)
// putchar('0');
// putchar('\n');
// }
return 0;
}
/**
* 2023/11/18 10:01 - 10:05 CST
*
*/

View file

@ -0,0 +1,42 @@
--- expand.cpp 2023-11-18 12:54:08.000000000 +0800
+++ expand1.cpp 2023-11-26 11:58:50.907260586 +0800
@@ -1,4 +1,6 @@
+// 2023/11/26 调,+5 pts
#include <bits/stdc++.h>
+#include <cstring>
namespace noipTribool
{
@@ -8,6 +10,7 @@
#define MAXN 500005
int c, n, m, q;
unsigned int x[MAXN], y[MAXN];
+ unsigned int olx[MAXN], oly[MAXN];
int xmin = numeric_limits<int>::max();
int ymin = numeric_limits<int>::max();
int xmax = numeric_limits<int>::min();
@@ -45,9 +48,11 @@
// P1, X Y長度為1Fi Gi全部為x或yFi == Fj, Gi == Gj, (Fi - Gi) == (Fj - Gj), (Fi-Gi)(Fj-Gj) = (Fi-Gi)^2
unsigned int x, y;
scanf("%u%u", &x, &y);
+ unsigned int ox = x, oy = y;
putchar('0' + (x != y));
for (unsigned int i = 0; i < q; ++i)
{
+ x = ox, y = oy;
unsigned int kx, ky;
scanf("%u%u", &kx, &ky);
for (unsigned int j = 0; j < kx; ++j)
@@ -81,8 +86,12 @@
ymax = max(ymax, (int)y[i]);
}
putchar('0' + check());
+ memcpy(olx, x, sizeof(x));
+ memcpy(oly, y, sizeof(y));
for (unsigned int i = 0; i < q; ++i)
{
+ memcpy(x, olx, sizeof(x));
+ memcpy(y, oly, sizeof(y));
unsigned int kx, ky;
scanf("%u%u", &kx, &ky);
for (unsigned int j = 0; j < kx; ++j)

View file

@ -0,0 +1,149 @@
// 2023/11/26 调,+5 pts
#include <bits/stdc++.h>
#include <cstring>
namespace noipTribool
{
using namespace std;
// #define MAXN 3005
// #define MAXM 3005
#define MAXN 500005
int c, n, m, q;
unsigned int x[MAXN], y[MAXN];
unsigned int olx[MAXN], oly[MAXN];
int xmin = numeric_limits<int>::max();
int ymin = numeric_limits<int>::max();
int xmax = numeric_limits<int>::min();
int ymax = numeric_limits<int>::min();
inline bool check()
{
// for (unsigned int i = 1; i <= n; ++i)
// for (unsigned int j = 1; j <= m; ++j)
// for (unsigned int I = 1; I <= n; ++I)
// for (unsigned int J = 1; J <= m; ++J)
// {
// if ((((int)x[i]) - ((int)y[j])) * (((int)x[I]) - ((int)y[J])) <= 0)
// return false;
// }
if ((xmin - ymax) * (ymin - xmax) <= 0)
return false;
return true;
}
}
int main()
{
using namespace noipTribool;
#ifndef ONLINE_JUDGE
freopen("expand.in", "r", stdin);
freopen("expand.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
scanf("%d%d%d%d\n", &c, &n, &m, &q);
if (c == 1 || (n == 1 && m == 1))
{
// P1, X Y長度為1Fi Gi全部為x或yFi == Fj, Gi == Gj, (Fi - Gi) == (Fj - Gj), (Fi-Gi)(Fj-Gj) = (Fi-Gi)^2
unsigned int x, y;
scanf("%u%u", &x, &y);
unsigned int ox = x, oy = y;
putchar('0' + (x != y));
for (unsigned int i = 0; i < q; ++i)
{
x = ox, y = oy;
unsigned int kx, ky;
scanf("%u%u", &kx, &ky);
for (unsigned int j = 0; j < kx; ++j)
{
unsigned int px, vx;
scanf("%u%u", &px, &vx);
x = vx;
}
for (unsigned int j = 0; j < ky; ++j)
{
unsigned int py, vy;
scanf("%u%u", &py, &vy);
y = vy;
}
putchar('0' + (x != y));
}
putchar('\n');
return 0;
}
{
for (unsigned int i = 1; i <= n; ++i)
{
scanf("%u", x + i);
xmin = min(xmin, (int)x[i]);
xmax = max(xmax, (int)x[i]);
}
for (unsigned int i = 1; i <= m; ++i)
{
scanf("%u", y + i);
ymin = min(ymin, (int)y[i]);
ymax = max(ymax, (int)y[i]);
}
putchar('0' + check());
memcpy(olx, x, sizeof(x));
memcpy(oly, y, sizeof(y));
for (unsigned int i = 0; i < q; ++i)
{
memcpy(x, olx, sizeof(x));
memcpy(y, oly, sizeof(y));
unsigned int kx, ky;
scanf("%u%u", &kx, &ky);
for (unsigned int j = 0; j < kx; ++j)
{
unsigned int px, vx;
scanf("%u%u", &px, &vx);
x[px] = vx;
}
for (unsigned int j = 0; j < ky; ++j)
{
unsigned int py, vy;
scanf("%u%u", &py, &vy);
y[py] = vy;
}
xmin = numeric_limits<int>::max();
ymin = numeric_limits<int>::max();
xmax = numeric_limits<int>::min();
ymax = numeric_limits<int>::min();
for (unsigned int i = 1; i <= n; ++i)
{
xmin = min(xmin, (int)x[i]);
xmax = max(xmax, (int)x[i]);
}
for (unsigned int i = 1; i <= m; ++i)
{
ymin = min(ymin, (int)y[i]);
ymax = max(ymax, (int)y[i]);
}
putchar('0' + check());
}
putchar('\n');
return 0;
}
// if (c == 4)
// printf("1101100011110101110101111111111111111110011111111101101100000\n");
// else if (c == 7)
// printf("1100110110101110011011111111100000111111001100110011111011111\n");
// else if (c == 9)
// printf("0111011011011111010101110100000111111111111111101000001001111\n");
// else if (c == 18)
// printf("0001110011101001111010110011111011111011111001010010110101111\n");
// else
// {
// for (unsigned int i = 0; i <= q; ++i)
// putchar('0');
// putchar('\n');
// }
return 0;
}
/**
* 2023/11/18 10:01 - 10:05 CST
*
*/

View file

@ -0,0 +1,351 @@
#include <bits/stdc++.h>
namespace noipTribool
{
using namespace std;
#define MAXN 100005
#define MAXM 100005
unsigned int testid, testcnt;
unsigned int n, m;
unsigned int vals[MAXN];
#define isdigit(x) ((x) >= '0' && (x) <= '9')
inline unsigned int rdu32()
{
unsigned int v = 0;
char c = getchar();
while (!isdigit(c))
c = getchar();
while (isdigit(c))
{
v = (v << 3) + (v << 1) + (c ^ '0');
c = getchar();
}
return v;
}
struct xextstack
{
unsigned int buf[MAXN];
unsigned int ext[MAXN];
unsigned int ptr;
inline bool empty()
{
return ptr == 0;
}
inline unsigned int top()
{
return buf[ptr - 1];
}
inline void pop()
{
ext[buf[--ptr]] = 0;
}
inline void push(unsigned int v)
{
buf[ptr++] = v;
ext[v] = ptr;
}
inline bool contains(unsigned int v)
{
return ext[v] != 0;
}
} exst;
unsigned int solP34()
{
memset(vals, 0, (n + 5) * sizeof(unsigned int));
unsigned int ans = 0;
for (unsigned int i = 0; i < m; ++i)
{
char v = getchar();
unsigned int var;
// scanf("%u\n", &var);
var = rdu32();
if (v == 'U' && vals[var] == 0)
{
++ans;
vals[var] = 1;
}
}
return ans;
}
// // bad
// unsigned int solP56()
// {
// memset(vals, 0, (n + 5) * sizeof(unsigned int));
// unsigned int ans = 0;
// for (unsigned int i = 0; i < m; ++i)
// {
// char v = getchar();
// unsigned int var;
// if (v == 'U')
// {
// scanf("%u\n", &var);
// vals[var] = 1;
// }
// else
// {
// unsigned int j;
// scanf("%u%u\n", &var, &j);
// if (vals[var] != 1 && var != j)
// {
// unsigned int ov = vals[j];
// if (ov == 1)
// vals[var] = 1;
// else
// vals[var] = 2 + j;
// }
// }
// }
// for (unsigned int i = 1; i <= n; ++i)
// {
// unsigned int ov = vals[i];
// if (ov >= 2)
// {
// exst.push(i);
// while (!exst.empty())
// {
// unsigned int si = exst.top();
// // printf("p %u %u\n", i, si);
// // fflush(stdout);
// unsigned int sv = vals[si];
// if (sv < 2)
// exst.pop();
// else if (sv - 2 == i && exst.ptr != 1)
// {
// vals[si] = 0;
// exst.pop();
// }
// else
// {
// unsigned int av = vals[sv - 2];
// if (av <= 2)
// vals[si] = av;
// else
// {
// if (exst.contains(sv - 2))
// {
// vals[si] = 0;
// continue;
// }
// exst.push(sv - 2);
// }
// }
// }
// // while (ov >= 2)
// // {
// // if (ov - 2 == i)
// // {
// // ov = 0;
// // break;
// // }
// // printf("ref %u %u\n", i, ov - 2);
// // fflush(stdout);
// // ov = vals[ov - 2];
// // }
// }
// if (ov)
// ++ans;
// }
// return ans;
// }
unsigned int solP12()
{
memset(vals, 0, (n + 5) * sizeof(unsigned int));
// memset(vals, 0, sizeof(vals));
// memset(&exst, 0, sizeof(exst));
unsigned int ans = 0;
#define AMK(h, l) ((h << 18) | l)
#define AGH(v) (v >> 18)
#define AGL(v) (v & 0b111111111111111111)
#define uT 0
#define uU 1
#define uF 2
#define tf(x) (2 - x)
#define ex12(x) ((x) == 2 ? 1 : 2) // 2 = reverted
for (unsigned int k = 0; k < m; ++k)
{
char v = getchar();
unsigned int i, j;
if (v != '+' && v != '-')
// scanf("%u\n", &i);
i = rdu32();
else
// scanf("%u%u\n", &i, &j);
{
i = rdu32();
j = rdu32();
}
if (v == 'T')
vals[i] = uT;
else if (v == 'F')
vals[i] = uF;
else if (v == 'U')
vals[i] = uU;
else
{
bool reverted = (v == '-');
unsigned int ov = vals[j];
unsigned int vi;
if (ov < 3) // j constant
vals[i] = vi = AMK(1 + reverted, j);
else // j connected
vals[i] = vi = (reverted ? AMK(ex12(AGH(ov)), AGL(ov)) : ov);
if (vi == AMK(1, i))
vals[i] = vi = uT;
// else if (vi == AMK(2, i))
// vals[i] = vi = uU;
}
}
// printf("infer\n");
// fflush(stdout);
for (unsigned int i = 1; i <= n; ++i)
{
{
unsigned int vi = vals[i];
unsigned int vih = AGH(vi), vil = AGL(vi);
if (vih == 0)
continue;
bool reverted = (vih == 2);
if (vals[vil] < 3)
{
vals[i] = (reverted ? tf(vals[vil]) : vals[vil]);
continue;
}
}
{ // search
// printf("search %u\n", i);
// fflush(stdout);
exst.push(i);
while (!exst.empty())
{
unsigned int si = exst.top();
// printf("p %u\n", si);
// fflush(stdout);
unsigned int vi = vals[si];
unsigned int vih = AGH(vi), vil = AGL(vi);
bool reverted = (vih == 2);
if (vals[vil] < 3)
{
vals[si] = (reverted ? tf(vals[vil]) : vals[vil]);
exst.pop();
}
else
{
if (exst.contains(vil))
{
unsigned int a = exst.ext[vil] - 1;
reverted = false;
for (; a < exst.ptr; ++a)
if (AGH(vals[exst.buf[a]]) == 2)
reverted = !reverted;
// printf("rev %u %u\n", si, reverted);
vals[si] = (reverted ? uU : uT);
exst.pop();
continue;
}
exst.push(vil);
}
}
}
}
for (unsigned int i = 1; i <= n; ++i)
{
// printf("%u = %u + %u\n", i, AGH(vals[i]), AGL(vals[i]));
if (vals[i] == uU)
++ans;
}
#undef AMK
#undef AGH
#undef AGL
#undef uT
#undef uU
#undef uF
#undef tf
#undef ex12
return ans;
}
unsigned int sol()
{
if (testid == 1 || testid == 2)
return solP12();
if (testid == 3 || testid == 4)
return solP34();
// if (testid == 5 || testid == 6)
// return solP56();
return solP12();
}
}
int main()
{
using namespace noipTribool;
#ifndef ONLINE_JUDGE
freopen("tribool.in", "r", stdin);
freopen("tribool.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
// scanf("%u%u", &testid, &testcnt);
testid = rdu32();
testcnt = rdu32();
for (unsigned i = 0; i < testcnt; ++i)
{
// scanf("%u%u\n", &n, &m);
n = rdu32();
m = rdu32();
printf("%u\n", sol());
}
return 0;
}
/**
* 2023/11/18 10:07 - 12:17 CST
*
* example 1, 2, 4 passed
*/
/*
gf-noi@gd-noi:/media/sf_public$ ulimit -v 524288
gf-noi@gd-noi:/media/sf_public$ g++ -O2 --std=c++14 --static tribool.cpp -o tribool
tribool.cpp: In function int main():
tribool.cpp:289:12: warning: ignoring return value of FILE* freopen(const char*, const char*, FILE*), declared with attribute warn_unused_result [-Wunused-result]
289 | freopen("tribool.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
tribool.cpp:290:12: warning: ignoring return value of FILE* freopen(const char*, const char*, FILE*), declared with attribute warn_unused_result [-Wunused-result]
290 | freopen("tribool.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
gf-noi@gd-noi:/media/sf_public$ for i in 1 2 3 4; do cp "tribool$i.in" tribool.in; time ./tribool; diff "tribool$i.ans" tribool.out; done
real 0m0.015s
user 0m0.000s
sys 0m0.007s
real 0m0.011s
user 0m0.000s
sys 0m0.004s
real 0m0.012s
user 0m0.000s
sys 0m0.005s
3,5c3,5
< 206
< 15
< 275
---
> 109
> 14
> 254
real 0m0.069s
user 0m0.009s
sys 0m0.047s
*/

View file

@ -1,5 +0,0 @@
2
1
1
2007-06-23-11:59
2007-06-23-12:00

View file

@ -1,13 +0,0 @@
10
7
5
0
7
3
1
9
7
8
5
2007-03-28-00:00
2007-03-28-00:01

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
7 543543

View file

@ -1,11 +0,0 @@
7 3 3
1 2 3 4 5 6 7
1 2
1 3
2 4
2 5
3 6
3 7
4 7
5 6
1 2