Submission #441913

#TimeUsernameProblemLanguageResultExecution timeMemory
441913cheetoseEvent Hopping 2 (JOI21_event2)C++17
100 / 100
1399 ms24044 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define X first #define Y second #define y0 y12 #define y1 y22 #define INF 987654321 #define PI 3.141592653589793238462643383279502884 #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c)) #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c)) #define MEM0(a) memset((a),0,sizeof(a)) #define MEM_1(a) memset((a),-1,sizeof(a)) #define ALL(a) a.begin(),a.end() #define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin()) #define SYNC ios_base::sync_with_stdio(false);cin.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> Pi; typedef pair<ll, ll> Pll; typedef pair<ld, ld> Pd; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<ld> Vd; typedef vector<Pi> VPi; typedef vector<Pll> VPll; typedef vector<Pd> VPd; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tuple<ll, ll, ll> LLL; typedef vector<iii> Viii; typedef vector<LLL> VLLL; typedef complex<double> base; const int MOD = 1000000007; ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; } int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 }; int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 }; Pll p[100000]; int d[200005][18]; int C(int l,int r){ int res=0; fdn(i,17,0,1){ if(d[l][i]<=r){ res|=1<<i; l=d[l][i]+1; } } return res; } int tree[524288],lazy[524288]; void propagation(int node,int S,int E){ if(lazy[node]!=0){ tree[node]+=lazy[node]*(E-S+1); if(S!=E){ lazy[2*node]+=lazy[node]; lazy[2*node+1]+=lazy[node]; } lazy[node]=0; } } void upd(int node,int S,int E,int i,int j,int val){ propagation(node,S,E); if(i>E || j<S) return; if(j>=E && i<=S){ lazy[node]+=val; propagation(node,S,E); return; } upd(2*node,S,(S+E)/2,i,j,val); upd(2*node+1,(S+E)/2+1,E,i,j,val); tree[node]=tree[2*node]+tree[2*node+1]; } int find(int node,int S,int E,int i,int j){ propagation(node,S,E); if(i>E || j<S)return 0; if(j>=E && i<=S)return tree[node]; return find(node*2,S,(S+E)/2,i,j)+find(2*node+1,(S+E)/2+1,E,i,j); } int N; int L(int x){ int l=0,r=x; while(l<=r){ int m=l+r>>1; if(find(1,0,N-1,m,x))l=m+1; else r=m-1; } return l; } int R(int x){ int l=x,r=N-1; while(l<=r){ int m=l+r>>1; if(find(1,0,N-1,x,m))r=m-1; else l=m+1; } return r; } int main(){ int n,k; scanf("%d%d",&n,&k); Vll vv; fup(i,0,n-1,1){ ll x,y; scanf("%lld%lld",&x,&y); x=3*x+1,y=3*y-1; p[i]=mp(x,y); vv.pb(x);vv.pb(y); } COMPRESS(vv); N=vv.size(); fup(i,0,N+1,1)fup(j,0,17,1)d[i][j]=N; VPi v; fup(i,0,n-1,1){ p[i].X=lower_bound(ALL(vv),p[i].X)-vv.begin(); p[i].Y=lower_bound(ALL(vv),p[i].Y)-vv.begin(); d[p[i].X][0]=min(d[p[i].X][0],(int)p[i].Y); } int now=N; fdn(i,N-1,0,1){ now=min(now,d[i][0]); d[i][0]=now; } fup(j,0,16,1){ fup(i,0,N-1,1){ d[i][j+1]=d[d[i][j]+1][j]; } } int tot=0; now=0; fdn(i,17,0,1){ if(d[now][i]<N){ tot|=1<<i; now=d[now][i]+1; } } if(tot<k)return !printf("-1\n"); int ans=0; fup(i,0,n-1,1){ if(ans==k)break; int x=p[i].X,y=p[i].Y; if(find(1,0,N-1,x,y))continue; int l=L(x-1),r=R(y+1); int c1=C(l,r),c2=C(l,x-1)+1+C(y+1,r); if(tot-c1+c2<k)continue; tot-=c1-c2; printf("%d\n",i+1); upd(1,0,N-1,x,y,1); ans++; } }

Compilation message (stderr)

event2.cpp: In function 'int C(int, int)':
event2.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
event2.cpp:47:2: note: in expansion of macro 'fdn'
   47 |  fdn(i,17,0,1){
      |  ^~~
event2.cpp: In function 'int L(int)':
event2.cpp:88:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |   int m=l+r>>1;
      |         ~^~
event2.cpp: In function 'int R(int)':
event2.cpp:97:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |   int m=l+r>>1;
      |         ~^~
event2.cpp: In function 'int main()':
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:107:2: note: in expansion of macro 'fup'
  107 |  fup(i,0,n-1,1){
      |  ^~~
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:116:2: note: in expansion of macro 'fup'
  116 |  fup(i,0,N+1,1)fup(j,0,17,1)d[i][j]=N;
      |  ^~~
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:116:16: note: in expansion of macro 'fup'
  116 |  fup(i,0,N+1,1)fup(j,0,17,1)d[i][j]=N;
      |                ^~~
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:118:2: note: in expansion of macro 'fup'
  118 |  fup(i,0,n-1,1){
      |  ^~~
event2.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
event2.cpp:124:2: note: in expansion of macro 'fdn'
  124 |  fdn(i,N-1,0,1){
      |  ^~~
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:128:2: note: in expansion of macro 'fup'
  128 |  fup(j,0,16,1){
      |  ^~~
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:129:3: note: in expansion of macro 'fup'
  129 |   fup(i,0,N-1,1){
      |   ^~~
event2.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
event2.cpp:135:2: note: in expansion of macro 'fdn'
  135 |  fdn(i,17,0,1){
      |  ^~~
event2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
event2.cpp:143:2: note: in expansion of macro 'fup'
  143 |  fup(i,0,n-1,1){
      |  ^~~
event2.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
event2.cpp:109:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |   scanf("%lld%lld",&x,&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...