답안 #555126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555126 2022-04-30T08:12:19 Z IvanJ Meteors (POI11_met) C++17
100 / 100
1782 ms 58012 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];
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]) break;
				}
				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

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);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16724 KB Output is correct
2 Correct 11 ms 16852 KB Output is correct
3 Correct 12 ms 16736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 16724 KB Output is correct
2 Correct 10 ms 16812 KB Output is correct
3 Correct 12 ms 16852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 18184 KB Output is correct
2 Correct 135 ms 20112 KB Output is correct
3 Correct 116 ms 19760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 19220 KB Output is correct
2 Correct 114 ms 19220 KB Output is correct
3 Correct 136 ms 20272 KB Output is correct
4 Correct 38 ms 18588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 18504 KB Output is correct
2 Correct 156 ms 20796 KB Output is correct
3 Correct 123 ms 17512 KB Output is correct
4 Correct 111 ms 20160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 17664 KB Output is correct
2 Correct 124 ms 19148 KB Output is correct
3 Correct 90 ms 17968 KB Output is correct
4 Correct 136 ms 21392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 993 ms 34304 KB Output is correct
2 Correct 604 ms 21476 KB Output is correct
3 Correct 588 ms 19908 KB Output is correct
4 Correct 1637 ms 54136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 958 ms 32768 KB Output is correct
2 Correct 609 ms 21588 KB Output is correct
3 Correct 501 ms 19188 KB Output is correct
4 Correct 1782 ms 58012 KB Output is correct