Submission #40459

#TimeUsernameProblemLanguageResultExecution timeMemory
40459IvanCMeteors (POI11_met)C++14
74 / 100
6073 ms48592 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct pergunta{ int ini,fim,meio,resp,id; pergunta(int _ini = 0,int _fim = 0){ ini = _ini; fim = _fim; meio = -1; resp = -1; } }; const int MAXN = 300010; vector<int> estados[MAXN]; vector<pergunta> P; ll seg[4*MAXN],lazy[4*MAXN]; int N,M,K,li[MAXN],ri[MAXN],ai[MAXN],qtd[MAXN],maximom; vector<int> bucket[MAXN]; inline void propagate(int pos,int left,int right){ seg[pos] += lazy[pos]; if(left != right){ lazy[2*pos] += lazy[pos]; lazy[2*pos+1] += lazy[pos]; } lazy[pos] = 0; } void build(int pos,int left,int right){ seg[pos] = lazy[pos] = 0; if(left == right) return; int mid = (left+right)/2; build(2*pos,left,mid); build(2*pos+1,mid+1,right); } void update(int pos,int left,int right,int i,int j,ll val){ propagate(pos,left,right); if(left > right || left > j || right < i) return; if(left >= i && right <= j){ lazy[pos] += val; propagate(pos,left,right); return; } int mid = (left+right)/2; update(2*pos,left,mid,i,j,val); update(2*pos+1,mid+1,right,i,j,val); } inline ll query(int pos,int left,int right,int x){ while(left != right){ propagate(pos,left,right); int mid = (left+right)/2; if(x <= mid){ right = mid; pos = 2*pos; } else{ left = mid + 1; pos = 2*pos + 1; } } propagate(pos,left,right); return seg[pos]; } void do_update(int i){ if(li[i] <= ri[i]){ update(1,1,M,li[i],ri[i],ai[i]); } else{ update(1,1,M,li[i],M,ai[i]); update(1,1,M,1,ri[i],ai[i]); } } void checa(int i){ ll tot = qtd[i]; for(int j : estados[i]){ tot -= query(1,1,M,j); if(tot <= 0) break; } if(tot <= 0){ P[i].resp = P[i].meio; P[i].fim = P[i].meio - 1; } else{ P[i].ini = P[i].meio + 1; } } int main(){ pergunta dummy(0,0); P.push_back(dummy); scanf("%d %d",&N,&M); for(int i = 1;i<=M;i++){ int x; scanf("%d",&x); estados[x].push_back(i); } for(int i = 1;i<=N;i++) scanf("%d",&qtd[i]); scanf("%d",&K); for(int i = 1;i<=N;i++){ pergunta davez(1,K); P.push_back(davez); } for(int i = 1;i<=K;i++){ scanf("%d %d %d",&li[i],&ri[i],&ai[i]); } int limite = ceil(log(K)/log(2)) + 1; for(int iteracao = 1;iteracao<=limite;iteracao++){ build(1,1,M); maximom = 0; for(int i = 1;i<=N;i++){ if(P[i].ini > P[i].fim){ continue; } P[i].meio = (P[i].ini + P[i].fim)/2; maximom = max(P[i].meio,maximom); bucket[P[i].meio].push_back(i); } for(int atualizacao = 1;atualizacao<=maximom;atualizacao++){ do_update(atualizacao); if(bucket[atualizacao].empty()) continue; while(!bucket[atualizacao].empty()){ int i = bucket[atualizacao].back(); bucket[atualizacao].pop_back(); checa(i); } } } for(int i = 1;i<=N;i++){ if(P[i].resp == -1) printf("NIE \n"); else printf("%d\n",P[i].resp); } return 0; }

Compilation message (stderr)

met.cpp: In function 'int main()':
met.cpp:88:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
met.cpp:91:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
                 ^
met.cpp:94:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1;i<=N;i++) scanf("%d",&qtd[i]);
                                             ^
met.cpp:95:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&K);
                ^
met.cpp:101:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&li[i],&ri[i],&ai[i]);
                                         ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...