QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#827358 | #7760. 化学实验 | ningago | 0 | 111ms | 11480kb | C++14 | 5.8kb | 2024-12-22 22:03:47 | 2024-12-22 22:03:47 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
return getchar();
#else
if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}
void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;
void putc(char c)
{
#ifdef LOCAL
putchar(c);
#else
*oS++ = c;
if(oS == oT) Flush();
#endif
#define putchar ERR
}
template <typename T = int> T read()
{
T x = 0, f = 1; char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
top = 0;
if(x < 0) putc('-'), x = -x;
if(!x) sta[top = 1] = 0;
for(; x; x /= 10) sta[++top] = x % 10;
for(; top; ) putc(sta[top--] ^ 48);
if(c) putc(c);
}
int readstr(char *s, int base)
{
int idx = base - 1; char c = getc();
for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
for(; isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
return idx - base + 1;
}
void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
for(; *s; s++)
{
if(*s != '%') { putc(*s); continue; }
s++; if(*s == 'd') print(x, 0);
else if(*s == 'c') putc(x);
printf(s + 1, rest ...);
return;
}
}
template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }
#define N 500010
int OP, n, m;
struct Tree
{
int f, ch[2], sz, lightsz, L;
}tr[N];
#define fa(k) tr[k].f
#define lson(k) tr[k].ch[0]
#define rson(k) tr[k].ch[1]
#define son(k, i) tr[k].ch[i]
void pushup(int k) { tr[k].sz = tr[lson(k)].sz + tr[rson(k)].sz + 1 + tr[k].lightsz; tr[k].L = lson(k) ? tr[lson(k)].L : k; }
bool notroot(int k) { return lson(fa(k)) == k || rson(fa(k)) == k; }
bool getid(int k) { return rson(fa(k)) == k; }
void rotate(int k)
{
int f = fa(k), gf = fa(f), id = getid(k), fid = getid(f), s = son(k, id ^ 1);
if(notroot(f)) son(gf, fid) = k;
fa(fa(fa(son(son(k, id ^ 1) = f, id) = s) = f) = k) = gf;
pushup(f); pushup(k);
}
void splay(int k) { for(; notroot(k); rotate(k)) if(notroot(fa(k))) rotate(getid(k) == getid(fa(k)) ? fa(k) : k); }
int access(int k) { int nx = 0; for(; k; k = fa(nx = k)) { splay(k); tr[k].lightsz += tr[rson(k)].sz - tr[nx].sz; rson(k) = nx; pushup(k); } return nx; }
int divide(int k, int z)
{
int res = k;
while(k)
{
if(k >= z) res = k, k = rson(k);
else k = lson(k);
}
return res;
}
void merge(int x, int y)
{
int las = 0, nx;
if(x) splay(x);
if(y) splay(y);
while(x || y)
{
if(tr[x].L < tr[y].L) x ^= y ^= x ^= y;
// printf("x = %d, y = %d (%d %d)\n", x, y, tr[x].L, tr[y].L);
x = divide(x, tr[y].L); splay(x);
// printf("x -> %d\n", x);
if(las) rson(las) = x, fa(x) = las, pushup(las);
splay(x); las = x;
if((nx = rson(x))) fa(rson(x)) = 0, rson(x) = 0;
pushup(x); x = nx; if(nx) splay(nx);
}
}
void solve()
{
// memset(h, idx = -1, sizeof(h));
OP = read(), n = read(), m = read();
for(int i = 1; i <= n; i++) fa(i) = n + 1, tr[i].sz = 1;
for(int i = 1; i <= n + 1; i++) tr[i].L = i;
tr[n + 1].sz = n + 1; tr[n + 1].lightsz = n;
int lastans = 0;
for(int i = 1, op, x, y; i <= m; i++)
{
op = read(), x = read(), y = read();
x = (x - 1 + OP * lastans) % n + 1;
y = (y - 1 + OP * lastans) % n + 1;
// printf("[%d %d %d]\n", op, x, y);
if(op == 1)
{
access(x);
// for(int i = 1; i <= n + 1; i++) printf("fa[%d] = %d, lson = %d, rson = %d, L = %d\n", i, fa(i), lson(i), rson(i), tr[i].L);
int p = access(y);
// for(int i = 1; i <= n + 1; i++) printf("fa[%d] = %d, lson = %d, rson = %d, L = %d\n", i, fa(i), lson(i), rson(i), tr[i].L);
// for(int i = 1; i <= n + 1; i++) printf("fa[%d] = %d, lson = %d, rson = %d, L = %d (%d %d)\n", i, fa(i), lson(i), rson(i), tr[i].L, tr[i].sz, tr[i].lightsz);
if(p == x || p == y) continue;
merge(x, y);
}
else
{
access(x);
splay(x);
int res = 0;
while(x)
{
if(x <= y) res += tr[x].sz - tr[lson(x)].sz, x = lson(x);
else x = rson(x);
}
print(lastans = res, '\n');
}
// printf("[%d %d]\n", tr[0].sz, tr[0].lightsz);
// for(int i = 1; i <= n + 1; i++) printf("fa[%d] = %d, lson = %d, rson = %d, L = %d (%d %d)\n", i, fa(i), lson(i), rson(i), tr[i].L, tr[i].sz, tr[i].lightsz);
}
}
void init()
{
}
char _ED_;
void mian()
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
init();
for(int T = 1; T; solve(), T--);
}
#ifdef int
#undef int
#endif
}
int main()
{
// freopen("tmp.in", "r", stdin);
// freopen("tmp.out", "w", stdout);
uvu::mian(); return 0;
}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 10
Accepted
time: 7ms
memory: 10040kb
input:
1 7500 7500 1 263 1446 1 6338 3037 1 5651 6129 1 572 3137 1 3159 5472 1 6038 4451 1 5988 5462 1 3873 1562 1 3516 5142 1 3375 2376 1 5832 1884 1 6243 3066 1 4001 6195 1 5301 6851 1 4382 2910 1 5299 562 1 452 335 1 3459 814 1 6681 6391 1 5816 4975 1 2244 1118 1 1410 1067 1 331 6324 1 6305 1294 1 4251 ...
output:
3984
result:
ok single line: '3984'
Test #2:
score: 0
Runtime Error
input:
1 750 7500 1 424 707 1 405 537 2 19 26 2 365 365 2 6 11 1 695 549 1 579 661 2 682 687 1 621 586 2 446 453 2 562 567 2 534 537 2 509 515 2 109 113 2 112 114 2 46 54 2 736 746 2 355 363 2 706 709 2 526 529 2 40 48 2 80 83 2 684 689 2 479 480 2 320 323 2 74 76 2 170 180 1 472 559 2 125 128 1 426 717 2 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ...
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 15
Accepted
time: 16ms
memory: 8088kb
input:
1 5000 100000 2 872 876 1 2895 4566 1 2676 1220 2 1852 1856 2 4153 4153 2 3675 3685 2 1489 1493 2 2782 2784 2 206 207 2 555 560 2 4149 4157 2 1875 1885 2 364 374 2 8 17 2 746 754 2 4785 4786 2 2394 2394 2 3386 3389 2 365 373 2 2290 2296 2 1419 1428 2 3651 3659 2 1922 1927 2 4877 4882 2 2597 2599 2 4...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 95001 lines
Test #12:
score: 0
Runtime Error
input:
1 5000 100000 2 4315 4323 2 1391 1401 2 294 302 2 1704 1711 2 748 748 2 3430 3437 2 2045 2051 2 996 1005 2 902 904 2 4674 4676 2 296 298 2 951 961 2 451 460 1 4152 3232 2 311 312 2 2061 2071 2 1604 1608 2 2441 2450 2 1706 1716 2 4119 4122 2 3922 3925 2 4864 4870 2 2045 2048 2 4492 4493 2 1194 1194 2...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 20
Accepted
time: 111ms
memory: 11480kb
input:
0 100000 100000 1 29135 32144 1 58340 30601 1 68869 18606 1 73019 84578 1 13050 79881 1 22773 20030 1 74542 28744 1 46491 64238 1 26985 17174 1 93308 48003 1 90547 4510 1 18373 35069 1 34019 14080 1 13461 19407 1 33811 60169 1 22131 76457 1 88085 38979 1 49749 20241 1 90505 42660 1 25889 75426 1 420...
output:
80930
result:
ok single line: '80930'
Test #22:
score: 0
Wrong Answer
time: 37ms
memory: 8148kb
input:
0 10000 100000 1 6042 9322 1 5723 6899 2 2207 2214 2 7557 7567 2 7648 7658 2 3150 3156 2 7555 7560 2 9657 9661 2 5681 5686 2 5736 5744 1 9993 9001 2 6887 6893 2 5765 5765 2 7983 7987 2 2427 2433 2 8236 8245 1 5381 8258 2 7503 7513 2 236 244 2 816 816 2 5139 5147 1 9243 6698 2 8713 8718 2 4569 4571 2...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 13863rd lines differ - expected: '160', found: '161'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%