제출 #40416

#제출 시각아이디문제언어결과실행 시간메모리
40416IvanC새로운 문제 (POI11_met)C++14
74 / 100
6089 ms65536 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,int _id = 0){ ini = _ini; fim = _fim; id = _id; meio = -1; resp = -1; } bool operator<(const pergunta &other)const{ return meio < other.meio; } }; 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]; 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 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); } ll query(int pos,int left,int right,int x){ propagate(pos,left,right); if(left == right) return seg[pos]; int mid = (left+right)/2; if(x <= mid) return query(2*pos,left,mid,x); else return query(2*pos+1,mid+1,right,x); } 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]); } } int main(){ 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,i); 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++){ for(int i = 1;i<=4*M;i++) seg[i] = lazy[i] = 0; for(int i = 0;i<N;i++){ if(P[i].ini > P[i].fim) P[i].meio = -1; P[i].meio = (P[i].ini + P[i].fim)/2; } sort(P.begin(),P.end()); int atualizacao = 1; for(int i = 0;i<N;i++){ if(P[i].meio == -1) continue; while(atualizacao <= P[i].meio){ do_update(atualizacao); atualizacao++; } ll tot = qtd[P[i].id]; for(int j : estados[P[i].id]){ 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; } } } for(int i = 0;i<N;i++){ qtd[P[i].id] = P[i].resp; } for(int i = 1;i<=N;i++){ if(qtd[i] == -1) printf("NIE\n"); else printf("%d\n",qtd[i]); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

met.cpp: In function 'int main()':
met.cpp:59: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:62:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
                 ^
met.cpp:65: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:66:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&K);
                ^
met.cpp:72: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...