Submission #555123

#TimeUsernameProblemLanguageResultExecution timeMemory
555123IvanJMeteors (POI11_met)C++17
74 / 100
965 ms35308 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];
int ans[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 - 1;
	
	memset(ans, -1, sizeof ans);
	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(m, -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 - 1, ans[x] = i + 1;	
			}
		}
		
		if(!flag) break;
	}
	
	for(int i = 0;i < n;i++) {
		if(ans[i] == -1) printf("NIE\n"); 
		else printf("%d\n", ans[i]);
	}
	return 0;
}

Compilation message (stderr)

met.cpp: In function 'int main()':
met.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
met.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   int x;scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
met.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%lld", need + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
met.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
met.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   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...