답안 #555124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555124 2022-04-30T08:09:59 Z IvanJ Meteors (POI11_met) C++17
74 / 100
966 ms 34224 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]) 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 16728 KB Output is correct
3 Correct 11 ms 16816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16724 KB Output is correct
2 Correct 11 ms 16752 KB Output is correct
3 Correct 11 ms 16804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 18032 KB Output is correct
2 Correct 135 ms 20056 KB Output is correct
3 Correct 109 ms 19716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 19148 KB Output is correct
2 Correct 119 ms 19148 KB Output is correct
3 Correct 171 ms 20280 KB Output is correct
4 Correct 39 ms 18608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 18508 KB Output is correct
2 Correct 163 ms 20684 KB Output is correct
3 Correct 121 ms 17368 KB Output is correct
4 Correct 112 ms 20164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 17684 KB Output is correct
2 Correct 137 ms 19156 KB Output is correct
3 Correct 91 ms 17940 KB Output is correct
4 Correct 144 ms 21392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 966 ms 34224 KB Output is correct
2 Incorrect 690 ms 21720 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 959 ms 33008 KB Output is correct
2 Incorrect 692 ms 21468 KB Output isn't correct
3 Halted 0 ms 0 KB -