Submission #339802

#TimeUsernameProblemLanguageResultExecution timeMemory
339802GioChkhaidzeSegments (IZhO18_segments)C++14
75 / 100
5043 ms11272 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define ll long long #define ordered_set tree < pair < int , int > , null_type,less < pair<int, int> > , rb_tree_tag,tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; const int inf = 2e9 + 1; const int N = 2e5 + 5; const int Sq = 333; int v[Sq][2][1900], vs[Sq][2], a[N][2], pr[N][2], c[N], A[N], L[Sq][2], R[Sq][2]; int n, t, tot, del, mid, res, ret, lo, hi, sq, Lq, Rq, Kq, ms, as, tp, id, x, 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; } main () { ordered_set o; scanf("%d %d",&n, &t); sq = 888, ms = 255; 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(); o.insert({c[u],u}); } else if (ty == 2) { scanf("%d",&idx); --cnt, id = idx; tp = 0, d(), tp = 1, d(); o.erase({c[id],id}); } 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(); Z = o.order_of_key({C,-1}); lastans = ans = cnt - (X + Y + Z); } printf("%d\n",ans); } } }

Compilation message (stderr)

segments.cpp:122:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  122 | main () {
      |       ^
segments.cpp: In function 'int main()':
segments.cpp:124:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  124 |  scanf("%d %d",&n, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:129:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  129 |   scanf("%d",&ty);
      |   ~~~~~^~~~~~~~~~
segments.cpp:132:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  132 |    scanf("%d %d",&a[u][0], &a[u][1]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:142:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  142 |    scanf("%d",&idx); --cnt, id = idx;
      |    ~~~~~^~~~~~~~~~~
segments.cpp:148:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  148 |    scanf("%d %d %d",&A, &B, &C);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...