Submission #1089112

#TimeUsernameProblemLanguageResultExecution timeMemory
1089112modwweNew Home (APIO18_new_home)C++17
Compilation error
0 ms0 KiB
#pragma GCC optimize("Ofast,unroll-loops") #include<bits/stdc++.h> //#define int long long //#define ll long long #define down cout<<'\n'; #define debug cout<<" cucuucucuuu",down #define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define modwwe int t;cin>>t; while(t--) #define bit(i,j) (i>>j&1) #define sobit(a) __builtin_popcountll(a) #define task "test" #define fin(x) freopen(x".inp","r",stdin) #define fou(x) freopen(x".ans","w",stdout) #define pb push_back #define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms"; using namespace std; #define getchar_unlocked getchar inline int scan() { char c = getchar_unlocked(); int x = 0; while(c<'0'||c>'9') { c=getchar_unlocked(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar_unlocked(); } return x; } void phongbeo(); const int inf=1e9; const int mod2=1e9+9; const int mod1=998244353; struct icd { long double a; int b; }; struct ib { int a; int b; }; struct ic { int a,b,c; }; struct id { int a,b,c,d; }; struct ie { int a,b,c,d,e; }; int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2,center; int i,s10,s12; int kk; int el=19; main() { #ifndef ONLINE_JUDGE // fin(task); // fou(task); #endif NHP /// cin>>s1; ///modwwe phongbeo(); checktime } vector<ic> v[900001]; vector<int> v2,v3; set<int> s[300002]; multiset<int>ss[300002]; vector<ib> ask[900001]; id a[300001]; int ans[300001]; ib b[300001]; struct IT { int t[1200001]; void upd(int node,int l,int r,int l1) { if(l==r) { if(ss[l].size()==0)t[node]=0; else t[node]=*ss[l].rbegin(); return; } int mid=l+r>>1; if(l1<=mid) upd(node<<1,l,mid,l1); else upd(node<<1|1,mid+1,r,l1); t[node]=max(t[node<<1],t[node<<1|1]); } int get(int node,int l,int r,int l1) { if(r<=l1) return t[node]; int mid=l+r>>1; if(mid+1<=l1) return max(get(node<<1|1,mid+1,r,l1),get(node<<1,l,mid,l1)); else return get(node<<1,l,mid,l1); } } st; void add2(int x,int y) { ss[x].insert(y); st.upd(1,1,n,x); } void dell2(int x,int y) { auto it=ss[x].lower_bound(y); ss[x].erase(it); st.upd(1,1,n,x); } void add(int x,int y) { cnt[y][x]++; if(cnt[y][x]>1) return; auto it=s[y].lower_bound(x); s2=-1; if(it!=s[y].end()) add2(x,*it),s2=*it; if(it!=s[y].begin()) { it--; auto it2=it; add2(*it2,x); if(s2!=-1) { dell2(*it2,s2); } } if(s[y].size()==2)dem++; if(cnt[y][x]==1) s[y].insert(x); } void del(int x,int y) { cnt[y][x]--; if(cnt[y][x]==0) { s[y].erase(x); if(s[y].size()==2) dem--; auto it=s[y].lower_bound(x); s2=-1; if(it!=s[y].end()) dell2(x,*it),s2=*it; if(it!=s[y].begin()) { it--; auto it2=it; dell2(*it2,x); if(s2!=-1) { add2(*it2,s2); } } } } bool check(int x,int y) { s2=lower_bound(v2.begin(),v2.end(),x-y)-v2.begin(); s2=max(s2,1); s3=st.get(1,1,n,s2); if(s3>v2.size()) return 0; return v2[s3-1]<=x+y; } int get(int x) { l=0; r=max(s12-x,x); while(l<=r) { int mid=l+r>>1; if(check(x,mid))r=mid-1; else l=mid+1; } return r+1; } void phongbeo() { n=scan(); k=scan(); m=scan(); v2.pb(0); for(int i=1; i<=n; i++) l=scan(),r=scan(),s2=scan(),s3=scan(),a[i]= {l,r,s2,s3},v3.pb(s2),v3.pb(s3+1),v2.pb(l),s12=max(s12,l); for(int i=1; i<=m; i++) l=scan(),r=scan(),b[i]= {l,r},v3.pb(r); sort(v2.begin(),v2.end()); v2.erase(unique(v2.begin(), v2.end()), v2.end()); sort(v3.begin(),v3.end()); v3.erase(unique(v3.begin(), v3.end()), v3.end()); for(int i=1; i<=n; i++) { s2=lower_bound(v3.begin(),v3.end(),a[i].c)-v3.begin()+1; s3=lower_bound(v3.begin(),v3.end(),a[i].d+1)-v3.begin()+1; l=lower_bound(v2.begin(),v2.end(),a[i].a)-v2.begin()+1; r=a[i].b; v[s2].pb({l,r,1}),v[s3].pb({l,r,-1}); } for(int i=1; i<=m; i++) { l=b[i].a; r=b[i].b; r=lower_bound(v3.begin(),v3.end(),r)-v3.begin()+1; ask[r].pb({l,i}); } for(int i=1; i<=k; i++) ss[1].insert(inf), s[i].insert(1),s[i].insert(inf); n++; st.upd(1,1,n,1); dem=0; for(int i=1; i<=v3.size(); i++) { for(auto f:v[i]) { if(f.c==1) { add(f.a,f.b); } else del(f.a,f.b); } for(auto f:ask[i]) { if(dem==k) ans[f.b]=get(f.a); else ans[f.b]=-1; } } for(int i=1; i<=m; i++) cout<<ans[i],down } /** 3 1 1 4 1 7 8 3 1 1 3 9 1 1 9 2 2 */

Compilation message (stderr)

new_home.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
new_home.cpp: In member function 'void IT::upd(int, int, int, int)':
new_home.cpp:98:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   98 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp: In member function 'int IT::get(int, int, int, int)':
new_home.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp: In function 'void add(int, int)':
new_home.cpp:125:5: error: 'cnt' was not declared in this scope; did you mean 'int'?
  125 |     cnt[y][x]++;
      |     ^~~
      |     int
new_home.cpp: In function 'void del(int, int)':
new_home.cpp:148:5: error: 'cnt' was not declared in this scope; did you mean 'int'?
  148 |     cnt[y][x]--;
      |     ^~~
      |     int
new_home.cpp: In function 'bool check(int, int)':
new_home.cpp:174:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  174 |     if(s3>v2.size()) return 0;
      |        ~~^~~~~~~~~~
new_home.cpp: In function 'int get(int)':
new_home.cpp:183:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  183 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp: In function 'void phongbeo()':
new_home.cpp:225:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  225 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~