Submission #48868

#TimeUsernameProblemLanguageResultExecution timeMemory
48868kriiiNew Home (APIO18_new_home)C++17
0 / 100
3921 ms204780 KiB
#include <stdio.h> #include <algorithm> #include <functional> #include <vector> #include <map> #include <set> using namespace std; int N,K,Q; int C,XP[1001001]; struct query{ int y,o,x,t; bool operator <(const query &t)const{ if (y == t.y) return o < t.o; return y < t.y; }; }qs[900900]; int qc; map<int, int> make[300300]; int ans[300300]; const int non = 500000000; const int Z = 1<<20; map<int, int> upc[Z]; map<int, int, greater<int> > downc[Z]; int up[Z*2],down[Z*2]; void push(int v, int u, int d, bool in) { int x = lower_bound(XP, XP+C, v) - XP; if (in) upc[x][u]++; else{ if (--upc[x][u] == 0) upc[x].erase(upc[x].find(u)); } if (upc[x].empty()) up[x+Z] = non; else up[x+Z] = upc[x].begin()->first; if (in) downc[x][u]++; else{ if (--downc[x][u] == 0) downc[x].erase(downc[x].find(u)); } if (downc[x].empty()) down[x+Z] = -non; else down[x+Z] = downc[x].begin()->first; x = (x + Z) / 2; while (x){ up[x] = min(up[x*2], up[x*2+1]); down[x] = max(down[x*2], down[x*2+1]); x /= 2; } } int out(int v) { int u = non, d = -non, p = lower_bound(XP,XP+C,v) - XP; { int x = p + Z, y = C-1 + Z; while (x < y){ if (x & 1) u = min(u, up[x++]); if (~y & 1) u = min(u, up[y--]); x /= 2; y /= 2; } if (x == y) u = min(u, up[x]); } { int x = Z, y = p + Z - 1; while (x < y){ if (x & 1) d = max(d, down[x++]); if (~y & 1) d = max(d, down[y--]); x /= 2; y /= 2; } if (x == y) d = max(d, down[x]); } return max(v-u,-v+d); } void mt(int s, int e, bool in) { push((s+e)/2,s,e,in); } int main() { scanf ("%d %d %d",&N,&K,&Q); for (int i=0;i<N;i++){ int x,t,a,b; scanf ("%d %d %d %d",&x,&t,&a,&b); x *= 2; qs[qc++] = {a,0,x,t}; qs[qc++] = {b+1,0,x,-t}; } for (int i=0;i<Q;i++){ int l,y; scanf ("%d %d",&l,&y); l *= 2; qs[qc++] = {y,1,l,i}; } sort(qs,qs+qc); for (int i=1;i<=K;i++){ make[i][-non] = make[i][non] = 1; } XP[C++] = -non; XP[C++] = non; XP[C++] = 0; for (int i=0;i<qc;i++){ auto &q = qs[i]; if (q.o == 0){ int x = q.x, t = q.t; if (t > 0){ int &c = make[t][x]; if (c == 0){ auto I = make[t].find(x); auto J = I, K = I; J--; K++; XP[C++] = (J->first + I->first) / 2; XP[C++] = (I->first + K->first) / 2; } c++; } else{ t = -t; int &c = make[t][x]; if (c == 1){ auto I = make[t].find(x); auto J = I, K = I; J--; K++; XP[C++] = (J->first + K->first) / 2; make[t].erase(I); } else c--; } } } sort(XP,XP+C); C = unique(XP,XP+C) - XP; int v = lower_bound(XP,XP+C,0) - XP; upc[v][-non] = downc[v][non] = K-1; mt(-non,non,true); for (int i=1;i<Z*2;i++) up[i] = non, down[i] = -non; int have = 0; for (int i=0;i<qc;i++){ auto &q = qs[i]; if (q.o == 0){ int x = q.x, t = q.t; if (t > 0){ if (make[t].size() == 2) have++; int &c = make[t][x]; if (c == 0){ auto I = make[t].find(x); auto J = I, K = I; J--; K++; mt(J->first,K->first,false); mt(J->first,I->first,true); mt(I->first,K->first,true); } c++; } else{ t = -t; int &c = make[t][x]; if (c == 1){ auto I = make[t].find(x); auto J = I, K = I; J--; K++; mt(J->first,I->first,false); mt(I->first,K->first,false); mt(J->first,K->first,true); make[t].erase(I); if (make[t].size() == 2) have--; } else c--; } } else{ ans[q.t] = have == K ? out(q.x) / 2 : -1; } } for (int i=0;i<Q;i++){ printf ("%d\n",ans[i]); } return 0; }

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d %d %d",&N,&K,&Q);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
new_home.cpp:89:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x,t,a,b; scanf ("%d %d %d %d",&x,&t,&a,&b);
                ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:95:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int l,y; scanf ("%d %d",&l,&y);
            ~~~~~~^~~~~~~~~~~~~~~
#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...