Submission #555123

# Submission time Handle Problem Language Result Execution time Memory
555123 2022-04-30T08:04:49 Z IvanJ Meteors (POI11_met) C++17
74 / 100
965 ms 35308 KB
#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

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 time Memory Grader output
1 Correct 11 ms 17876 KB Output is correct
2 Correct 11 ms 17876 KB Output is correct
3 Correct 11 ms 17876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 17980 KB Output is correct
2 Correct 11 ms 17876 KB Output is correct
3 Correct 13 ms 18004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 19308 KB Output is correct
2 Correct 155 ms 21392 KB Output is correct
3 Correct 110 ms 20940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 20296 KB Output is correct
2 Correct 133 ms 20428 KB Output is correct
3 Correct 182 ms 21448 KB Output is correct
4 Correct 38 ms 19784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 19672 KB Output is correct
2 Correct 146 ms 21960 KB Output is correct
3 Correct 149 ms 18652 KB Output is correct
4 Correct 112 ms 21384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 18864 KB Output is correct
2 Correct 139 ms 20320 KB Output is correct
3 Correct 89 ms 19092 KB Output is correct
4 Correct 142 ms 22624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 965 ms 35308 KB Output is correct
2 Incorrect 603 ms 22768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 903 ms 34108 KB Output is correct
2 Incorrect 646 ms 22760 KB Output isn't correct
3 Halted 0 ms 0 KB -