Submission #555081

# Submission time Handle Problem Language Result Execution time Memory
555081 2022-04-30T06:44:38 Z myungwoo Meteors (POI11_met) C++17
74 / 100
1018 ms 43416 KB
#include <bits/stdc++.h>
using namespace std;

using lld = long long;

constexpr int MAXN = 300005;
int N, M, Q;
int O[MAXN], P[MAXN];
vector<int> locations[MAXN];
tuple<int, int, int> queries[MAXN];
vector<int> points[MAXN];

struct BIT{
	BIT(int sz): sz(sz), tree(sz+1){}
	void update(int n, int v){
		for (;n<=sz;n+=n&-n) tree[n] += v;
	}
	void update(int l, int r, int v){
		update(l, v), update(r+1, -v);
	}
	lld get(int n){
		lld ret = 0;
		for (;n;n^=n&-n) ret += tree[n];
		return ret;
	}
	void clear(){
		fill(begin(tree), end(tree), 0);
	}
	int sz;
	vector<lld> tree;
};

int main(){
    scanf("%d%d", &N, &M);
	for (int i=1;i<=M;i++) scanf("%d", O+i), locations[O[i]].push_back(i);
	for (int i=1;i<=N;i++) scanf("%d", P+i);
	scanf("%d", &Q);
	for (int i=1;i<=Q;i++){
		auto& [l, r, a] = queries[i];
		scanf("%d%d%d", &l, &r, &a);
	}
	BIT bit(M);
	vector<int> S(N+1, 1), E(N+1, Q), ans(N+1);
	for (;;){
		bool done = 1;
		for (int i=1;i<=N;i++) if (S[i] <= E[i]){
			int m = S[i]+E[i] >> 1;
			done = 0;
			points[m].push_back(i);
		}
		if (done) break;
		for (int q=1;q<=Q;q++){
			auto [l, r, a] = queries[q];
			if (l <= r) bit.update(l, r, a);
			else bit.update(l, M, a), bit.update(1, r, a);
			for (int i: points[q]){
				lld cnt = 0;
				for (int loc: locations[i]) cnt += bit.get(loc);
				if (cnt >= P[i]) E[i] = q-1, ans[i] = q;
				else S[i] = q+1;
			}
			points[q].clear();
		}
		bit.clear();
	}
	for (int i=1;i<=N;i++){
		if (ans[i]) printf("%d\n", ans[i]);
		else puts("NIE");
	}
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:47:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |    int m = S[i]+E[i] >> 1;
met.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
met.cpp:35:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  for (int i=1;i<=M;i++) scanf("%d", O+i), locations[O[i]].push_back(i);
      |                         ~~~~~^~~~~~~~~~~
met.cpp:36:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  for (int i=1;i<=N;i++) scanf("%d", P+i);
      |                         ~~~~~^~~~~~~~~~~
met.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
met.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d%d%d", &l, &r, &a);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 9 ms 14420 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14420 KB Output is correct
2 Correct 10 ms 14492 KB Output is correct
3 Correct 9 ms 14552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 17140 KB Output is correct
2 Correct 119 ms 19656 KB Output is correct
3 Correct 106 ms 19084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 18536 KB Output is correct
2 Correct 98 ms 18480 KB Output is correct
3 Correct 144 ms 19764 KB Output is correct
4 Correct 38 ms 17292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 17608 KB Output is correct
2 Correct 92 ms 20300 KB Output is correct
3 Correct 48 ms 15604 KB Output is correct
4 Correct 96 ms 19532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 16888 KB Output is correct
2 Correct 98 ms 18596 KB Output is correct
3 Correct 71 ms 17240 KB Output is correct
4 Correct 116 ms 20944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 972 ms 43416 KB Output is correct
2 Incorrect 676 ms 30552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1018 ms 41768 KB Output is correct
2 Incorrect 658 ms 29136 KB Output isn't correct
3 Halted 0 ms 0 KB -