이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 2e9 + 1;
const int N = 2e5 + 5;
const int Sq = 555;
ll x;
unordered_map < int , int > G;
int v[180][3][2500], vs[180][3], a[N][3], pr[N][3], c[N], A[N], L[Sq][3], R[Sq][3];
int n, t, tot, del, mid, res, ret, lo, hi, sq, Lq, Rq, Kq, ms, as, tp, id, y, bl, j, k;
bool cmp1(int x, int y) {
return a[x][tp] < a[y][tp];
}
bool cmp2(int x, int y) {
return c[x] < c[y];
}
inline void Restart() {
for (tp = 0; tp < 2; ++tp) {
as = 0;
for (bl = 0; bl < ms; ++bl) {
for (j = 0; j < vs[bl][tp]; ++j)
A[as] = v[bl][tp][j], ++as;
vs[bl][tp] = 0;
}
if (as) sort(A , A + as, cmp1);
for (j = 0; j < as; ++j) {
bl = j / sq;
v[bl][tp][vs[bl][tp]++] = A[j];
pr[A[j]][tp] = bl;
}
for (bl = 0; bl < ms; ++bl) {
if (!vs[bl][tp]) continue;
R[bl][tp] = -inf, L[bl][tp] = inf;
for (j = 0; j < vs[bl][tp]; ++j) {
y = a[v[bl][tp][j]][tp];
A[j] = v[bl][tp][j];
if (R[bl][tp] < y) R[bl][tp] = y;
if (L[bl][tp] > y) L[bl][tp] = y;
}
sort(A, A + vs[bl][tp], cmp2);
for (j = 0; j < vs[bl][tp]; ++j)
v[bl][tp][j] = A[j];
}
}
}
inline void p() {
k = c[id], x = a[id][tp];
for (bl = 0; bl < ms; ++bl)
if (!vs[bl][tp] || x <= R[bl][tp]) {
if (!vs[bl][tp]) R[bl][tp] = L[bl][tp] = x;
pr[id][tp] = bl;
v[bl][tp][vs[bl][tp]++] = id;
j = vs[bl][tp] - 1;
while (0 < j && c[v[bl][tp][j-1]] > k)
swap(v[bl][tp][j-1], v[bl][tp][j]), --j;
if (x < L[bl][tp]) L[bl][tp] = x;
return ;
}
}
inline void d() {
k = c[id], x = a[id][tp];
for (bl = 0; bl < ms; ++bl)
if (pr[id][tp] == bl) {
for (j = 0; j + 1 < vs[bl][tp]; ++j)
if (v[bl][tp][j] == id) swap(v[bl][tp][j], v[bl][tp][j + 1]);
--vs[bl][tp];
if (vs[bl][tp]) {
R[bl][tp] = -inf, L[bl][tp] = inf;
for (j = 0; j < vs[bl][tp]; ++j) {
y = a[v[bl][tp][j]][tp];
if (R[bl][tp] < y) R[bl][tp] = y;
if (L[bl][tp] > y) L[bl][tp] = y;
}
}
return ;
}
}
int g() {
if (Lq > Rq) return 0;
ret = 0;
for (bl = 0; bl < ms; ++bl) {
if (!vs[bl][tp] || R[bl][tp] < Lq || Rq < L[bl][tp]) continue;
if (Lq <= L[bl][tp] && R[bl][tp] <= Rq) {
lo = 0, hi = vs[bl][tp] - 1, res = 0;
while (lo <= hi) {
mid = ((lo + hi) >> 1);
if (c[v[bl][tp][mid]] < Kq)
res = lo = mid + 1;
else
hi = mid - 1;
}
ret += vs[bl][tp] - res;
}
else {
for (j = 0; j < vs[bl][tp]; ++j) {
id = v[bl][tp][j];
if (c[id] < Kq) continue;
if (tp && a[id][1] <= Rq) ++ret;
if (!tp && Lq <= a[id][0]) ++ret;
}
}
}
return ret;
}
void up() {
while (x <= inf) {
G[x] += del;
x += (x & -x);
}
}
int gt() {
res = 0;
while (x > 0) {
res += G[x];
x -= (x & -x);
}
return res;
}
main () {
scanf("%d %d",&n, &t);
sq = 1200, ms = 170;
int lastans = 0, ans = 0, cnt = 0, u = 0, idx, ty, X, Y, Z, A, B, C;
for (int i = 0; i < n; ++i) {
if (!(i % sq)) Restart();
scanf("%d",&ty);
if (ty == 1) {
id = ++u, ++cnt;
scanf("%d %d",&a[u][0], &a[u][1]);
a[u][0] = (a[u][0] ^ (t * lastans));
a[u][1] = (a[u][1] ^ (t * lastans));
if (a[u][0] > a[u][1]) swap(a[u][0], a[u][1]);
c[u] = (a[u][1] - a[u][0] + 1);
tp = 0, p(), tp = 1, p();
del = 1, x = c[u], up();
}
else
if (ty == 2) {
scanf("%d",&idx); --cnt, id = idx;
tp = 0, d(), tp = 1, d();
del = -1, x = c[id], up();
}
else
if (ty == 3) {
scanf("%d %d %d",&A, &B, &C);
A = (A ^ (t * lastans));
B = (B ^ (t * lastans));
if (A > B) swap(A, B);
if (B - A + 1 < C) lastans = ans = 0;
else {
tp = 0, Lq = B - C + 2, Rq = 2e9, Kq = C, X = g();
tp = 1, Lq = 0, Rq = A + C - 2, Kq = C, Y = g();
x = C - 1, Z = gt();
lastans = ans = cnt - (X + Y + Z);
}
printf("%d\n",ans);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp:136:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
136 | main () {
| ^
segments.cpp: In function 'int main()':
segments.cpp:137:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
137 | scanf("%d %d",&n, &t);
| ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:142:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
142 | scanf("%d",&ty);
| ~~~~~^~~~~~~~~~
segments.cpp:145:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
145 | scanf("%d %d",&a[u][0], &a[u][1]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:155:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
155 | scanf("%d",&idx); --cnt, id = idx;
| ~~~~~^~~~~~~~~~~
segments.cpp:161:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
161 | scanf("%d %d %d",&A, &B, &C);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |