Submission #555124

#TimeUsernameProblemLanguageResultExecution timeMemory
555124IvanJMeteors (POI11_met)C++17
74 / 100
966 ms34224 KiB
#include<bits/stdc++.h> #define pb push_back #define x first #define y second using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 3e5 + 5; int n, m, k; vector<int> own[maxn]; ll need[maxn]; pair<ii, int> qs[maxn]; int L[maxn], R[maxn]; vector<int> A[maxn]; ll fwt[maxn]; void update(int x, ll v) { x++; for(;x < maxn;x += (x & -x)) fwt[x] += v; } ll query(int x) { x++; ll ret = 0; for(;x > 0;x -= (x & -x)) ret += fwt[x]; return ret; } int main() { scanf("%d %d", &n, &m); for(int i = 0;i < m;i++) { int x;scanf("%d", &x); x--, own[x].pb(i); } for(int i = 0;i < n;i++) scanf("%lld", need + i); scanf("%d", &k); for(int i = 0;i < k;i++) { int l, r, a; scanf("%d %d %d", &l, &r, &a); l--, r--; qs[i] = {{l, r}, a}; } for(int i = 0;i < n;i++) L[i] = 0, R[i] = k; while(true) { for(int i = 0;i < maxn;i++) fwt[i] = 0; int flag = 0; for(int i = 0;i < n;i++) if(L[i] != R[i]) A[(L[i] + R[i]) / 2].pb(i); for(int i = 0;i < k;i++) { if(qs[i].x.x > qs[i].x.y) { update(qs[i].x.x, qs[i].y); update(0, qs[i].y); update(qs[i].x.y + 1, -qs[i].y); } else { update(qs[i].x.x, qs[i].y); update(qs[i].x.y + 1, -qs[i].y); } while(A[i].size()) { flag = 1; int x = A[i].back();A[i].pop_back(); ll sum = 0; for(int y : own[x]) sum += query(y); if(sum < need[x]) L[x] = i + 1; else R[x] = i; } } if(!flag) break; } for(int i = 0;i < n;i++) { if(L[i] == k) printf("NIE\n"); else printf("%d\n", L[i] + 1); } return 0; }

Compilation message (stderr)

met.cpp: In function 'int main()':
met.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
met.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   int x;scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
met.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%lld", need + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
met.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
met.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%d %d %d", &l, &r, &a);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...