Submission #868128

#TimeUsernameProblemLanguageResultExecution timeMemory
868128sleepntsheepSegments (IZhO18_segments)C11
100 / 100
1323 ms9712 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,tune=native") #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #define N 200005 int V, n, t, na, nc; struct line { int l, r, w; } a[N], c[9900]; int o[N][2]; int e[N], f[N], we[N], wf[N], pf_[N], sz[9900], *pf = pf_+1; static inline int max(int a, int b) { return b>a?b:a; } static inline int min(int a, int b) { return b<a?b:a; } int compare_length(const void *a0, const void *b0) { const struct line *a = (const struct line*)a0, *b = (const struct line*)b0; return ((a->r - a->l) - (b->r - b->l)); } int compare_left_increasing_index(const void *a0, const void *b0) { const int aa = *(const int*)a0, bb = *(const int*)b0; return a[aa].l - a[bb].l; } int compare_right_increasing_index(const void *a0, const void *b0) { const int aa = *(const int*)a0, bb = *(const int*)b0; return a[aa].r - a[bb].r; } static inline void rebuild() { for (; nc;) a[na++] = c[--nc]; qsort(a, na, sizeof *a, compare_length); memset(sz, 0, sizeof *sz * (na / V + 1)); for (int i = 0; i < na; ++i) e[i] = f[i] = i, ++sz[i/V]; pf[0] = a[0].w; for (int i = 1; i < na; ++i) pf[i] = pf[i-1] + a[i].w; for (int i = 0; i * V <= na; ++i) { qsort(e+i*V, sz[i], sizeof *e, compare_left_increasing_index); qsort(f+i*V, sz[i], sizeof *f, compare_right_increasing_index); we[i*V+sz[i]-1] = a[e[i*V+sz[i]-1]].w; for (int j = i*V+sz[i]-1; --j >= i*V;) we[j] = we[j+1] + a[e[j]].w; wf[i*V] = a[f[i*V]].w; for (int j = i*V+1; j < i*V+sz[i]; ++j) wf[j] = wf[j-1] + a[f[j]].w; } } int main(void) { scanf("%d%d", &n, &t); V = 7000; for (int id = 1, S = 0, z = 0, lastans = 0, op, x, y, k, l, r; n--;) { scanf("%d%d", &op, &x); switch (op) { case 1: scanf("%d", &y); l = x ^ (t * lastans), r = y ^ (t * lastans); if (l>r) { int t=l;l=r;r=t;} c[nc++] = (struct line){l, r, 1}; o[id][0] = l, o[id][1] = r; ++id; if (nc == V) rebuild(); ++S; break; case 2: c[nc++] = (struct line){o[x][0], o[x][1], -1}; if (nc == V) rebuild(); --S; break; default: scanf("%d%d", &y, &k); z=0; l = x ^ (t * lastans), r = y ^ (t * lastans); if (l>r) { int t=l;l=r;r=t;} /* count in static */ { int Z = na; for (int L = 0, R = na-1; L <= R; ) { int M = (L+R)/2; if (a[M].r - a[M].l + 1 >= k) R = M - 1, Z = M; else L = M + 1; } if (Z != na) { int zb = Z/V, sb = zb+1; for (struct line *j = a + Z; j < a + sb * V; ++j) z -= (min(j->r, r) - max(j->l, l) + 1 < k) * j->w; for (int j = sb, cnt; j * V <= na + 1; ++j) { /* r - j->l + 1 < k === j->l > r - k + 1 */ for (int L = (cnt = 0), R = sz[j]-1; L <= R;) { int M = (L+R)/2; if (a[e[j*V+M]].l > r - k + 1) R = M - 1, cnt = we[j*V+M]; else L = M + 1; } z -= cnt; /* j->r - l + 1 < k === j->l < k + l - 1 */ for (int L = (cnt = 0), R = sz[j]-1; L <= R;) { int M = (L+R)/2; if (a[f[j*V+M]].r < k + l - 1) L = M + 1, cnt = wf[j*V+M]; else R = M - 1; } z -= cnt; } } z -= pf[Z-1]; } /* count in buffer */ for (struct line *j = c; j < c + nc; ++j) z -= (min(j->r, r) - max(j->l, l) + 1 < k) * j->w; printf("%d\n", lastans = (z += S)); break; } } return 0; }

Compilation message (stderr)

segments.c: In function 'main':
segments.c:57:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d%d", &n, &t);
      |     ^~~~~~~~~~~~~~~~~~~~~
segments.c:62:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d%d", &op, &x);
      |         ^~~~~~~~~~~~~~~~~~~~~~
segments.c:66:17: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |                 scanf("%d", &y);
      |                 ^~~~~~~~~~~~~~~
segments.c:80:17: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |                 scanf("%d%d", &y, &k); z=0;
      |                 ^~~~~~~~~~~~~~~~~~~~~
#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...