QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462966 | #5022. 【模板】线段树 | ningago | 0 | 10ms | 12296kb | C++14 | 5.3kb | 2024-07-04 10:35:20 | 2024-07-04 10:35:20 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <cctype>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
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
}
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 *= -1;
if(!x) sta[++top] = 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 ckmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> void ckmax(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 250010
#define B 1110
const int T = 2;
const int len = 1 << T;
int n, m, idx;
int a[N], asum[B][len + 5], L[N], R[N], belong[N];
int sum[B][len + 5];
std::vector <int> vec[B];
int queryR(int b) { /* printf("queryR(%d %d) = %d\n", L[b], R[b], asum[b][(int)vec[b].size() % len] ^ sum[b][(int)(vec[b].size() + 1) % len]); */
return asum[b][(int)vec[b].size() % len] ^ sum[b][(int)(vec[b].size() + 1) % len]; }
void rebuild(int b)
{
for(int i = 0; i < len; i++) sum[b][i] = 0, asum[b][i] = a[R[b] - i];
for(int j = 0; j < T; j++) for(int i = 0; i < len; i++) if(i >> j & 1) asum[b][i] ^= asum[b][i ^ (1 << j)];
}
void pushdown(int b)
{
// printf("pushdown([%d %d])\n", L[b], R[b]);
static int tmp[B], m, v[N];
m = vec[b].size(); if(!m) return;
for(int i = L[b]; i <= R[b]; i++) tmp[i - L[b]] = a[i];
for(int j = 0; j < T; j++) if(m >> j & 1) for(int i = 0; i < len; i++) if(i >> j & 1) tmp[i] ^= tmp[i ^ (1 << j)];
for(int i = 0; i < len; i++) v[i] = 0;
for(m = 0; !vec[b].empty(); vec[b].pop_back()) v[m++] = vec[b].back();
for(int j = 0; (1 << j) < m; j++) for(int i = 0; i < m; i++) if(!(i >> j & 1)) v[i] ^= v[i ^ (1 << j)];
for(int i = 0; i < len; i++) tmp[i] ^= v[i];
for(int i = L[b] ; i <= R[b]; i++) a[i] = tmp[i - L[b]];
rebuild(b);
}
void brute(int v, int l, int r)
{
pushdown(belong[l]);
for(int i = r; i > l; i--) a[i] ^= a[i - 1];
a[l] ^= v;
rebuild(belong[l]);
}
void change(int l, int r)
{
static int tmp[N];
if(belong[l] == belong[r]) return brute(0, l, r);
for(int i = belong[l]; i < belong[r]; i++) tmp[i] = queryR(i);
brute(0, l, R[belong[l]]); brute(tmp[belong[r] - 1], L[belong[r]], r);
for(int b = belong[l] + 1; b < belong[r]; b++) vec[b].push_back(tmp[b - 1]), sum[b][(int)vec[b].size() % len] ^= tmp[b - 1];
}
void solve()
{
n = read(), m = read();
for(int i = 1; i <= n; i++) a[i] = read();
for(int i = 1; i <= n; i++) belong[i] = (i - 1) / len + 1;
for(int i = 1; i <= belong[n]; i++) L[i] = (i - 1) * len + 1, R[i] = i * len;
for(int i = n + 1; i <= R[belong[n]]; i++) belong[i] = belong[n];
idx = belong[n];
for(int b = 1; b <= idx; b++) rebuild(b);
for(int i = 1, op, x, y; i <= m; i++)
{
op = read(), x = read();
if(op == 1) { y = read(); change(x, y); /* printf("change(%d %d) ed\n", x, y); */ }
else { /* printf("x = %d\n", x); */ pushdown(belong[x]); print(a[x], '\n'); }
}
for(int i = 1; i <= idx; i++) pushdown(i);
for(int i = 1; i <= n; i++) print(a[i], '\n');
}
void init()
{
read();
}
char _ED_;
void mian()
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
init();
int T = 1;
for(; T; solve(), T--);
}
#ifdef int
#undef int
#endif
}
int main()
{
uvu::mian(); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 2ms
memory: 11936kb
input:
1 6 6 1 1 5 1 9 4 2 5 1 2 5 2 4 1 3 6 2 6 1 1 6
output:
9 4 12 1 0 5 4 12 0
result:
ok 9 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 10000kb
input:
1 999 997 898798734 979577086 45974352 1013270193 1053191143 533594258 372426673 947830633 122319874 368651315 866424479 109724831 427664962 558099346 764830489 326451620 322471751 525780385 746941281 670254345 586958579 979544209 743892216 436404384 291681381 979530194 998929567 367716728 909076993...
output:
1015342581 962986689 965094083 871356796 835210392 172023195 63088572 606096781 569607283 436055720 154605892 663158209 154605892 776365236 281312240 62398687 182713417 604764772 816533315 793514230 325061861 806973284 91749226 283750235 198953311 170342298 432592070 809908556 683302450 40932811 669...
result:
ok 1996 numbers
Test #3:
score: -8
Wrong Answer
time: 2ms
memory: 12296kb
input:
1 999 997 89872218 906651903 120274311 490547919 291584020 755757065 24942887 707247173 763024744 68250332 114193028 999245166 140381610 171802205 399965713 299821903 907998064 906075056 427270276 335420206 708713870 492555323 359637714 197212814 35225369 1011322274 912003632 633998134 1026276199 85...
output:
89872218 860962725 120274311 490547919 978745892 924706625 285879949 707247173 350022657 45776587 523375993 1022413584 295498754 893044441 427030065 974258690 139644991 656627749 938162008 283830820 665224812 307730048 814275953 333487846 20189081 1036529735 521663886 718626816 868664991 780580980 4...
result:
wrong answer 7th numbers differ - expected: '610771729', found: '285879949'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 4ms
memory: 9272kb
input:
2 249998 99999 1048488450 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
result:
wrong answer Answer contains longer sequence [length = 300080], but output contains 0 elements
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 0ms
memory: 9136kb
input:
3 250000 99999 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1...
output:
result:
wrong answer Answer contains longer sequence [length = 300215], but output contains 0 elements
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 3ms
memory: 9252kb
input:
4 249996 99997 309331355 195839266 912372930 57974187 363345291 954954162 650621300 389049294 821214285 263720748 231045308 844370953 768579771 664766522 681320982 124177317 32442094 297873605 743179832 1073656106 443742270 235746807 1054294813 974443618 422427461 307448375 1018255356 20105813 36821...
output:
result:
wrong answer Answer contains longer sequence [length = 299980], but output contains 0 elements
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 10ms
memory: 11268kb
input:
5 249997 99997 860563869 428592873 58576739 761578583 47999879 294581118 988847649 569566599 640106250 440172702 178219106 966598261 763325707 846927552 877923116 145156535 246778542 25949847 507939778 116507169 555239769 259969305 328955819 171606729 535970481 121608060 4437163 370976515 713807003 ...
output:
result:
wrong answer Answer contains longer sequence [length = 249997], but output contains 0 elements
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%