Submission #555100

# Submission time Handle Problem Language Result Execution time Memory
555100 2022-04-30T07:24:46 Z myungwoo Meteors (POI11_met) C++17
100 / 100
1691 ms 59192 KB
#include <bits/stdc++.h>
using namespace std;

using lld = long long;

constexpr int MAXN = 300005;
int N, M, Q;
int 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;
	}
	int sz;
	vector<lld> tree;
};

int main(){
	scanf("%d%d", &N, &M);
	for (int i=1;i<=M;i++){
		int o; scanf("%d", &o);
		locations[o].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);
	}

	vector<int> S(N+1, 1), E(N+1, Q), ans(N+1);
	for (;;){
		int last = 0;
		for (int i=1;i<=N;i++) if (S[i] <= E[i]){
			int m = S[i]+E[i] >> 1;
			last = max(last, m);
			points[m].push_back(i);
		}
		if (!last) break;
		BIT bit(M);
		for (int q=1;q<=last;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 sum = 0;
				for (int loc: locations[i]){
					sum += bit.get(loc);
					if (sum >= P[i]) break;
				}
				if (sum >= P[i]) E[i] = q-1, ans[i] = q;
				else S[i] = q+1;
			}
			points[q].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:48:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |    int m = S[i]+E[i] >> 1;
met.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
met.cpp:34:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   int o; scanf("%d", &o);
      |          ~~~~~^~~~~~~~~~
met.cpp:37:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  for (int i=1;i<=N;i++) scanf("%d", P+i);
      |                         ~~~~~^~~~~~~~~~~
met.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
met.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   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 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 16300 KB Output is correct
2 Correct 102 ms 18628 KB Output is correct
3 Correct 88 ms 17828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 17272 KB Output is correct
2 Correct 91 ms 17292 KB Output is correct
3 Correct 94 ms 18572 KB Output is correct
4 Correct 44 ms 16708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 16572 KB Output is correct
2 Correct 85 ms 19008 KB Output is correct
3 Correct 29 ms 15040 KB Output is correct
4 Correct 91 ms 18212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 15620 KB Output is correct
2 Correct 90 ms 17172 KB Output is correct
3 Correct 72 ms 16016 KB Output is correct
4 Correct 106 ms 19616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 853 ms 35728 KB Output is correct
2 Correct 142 ms 21544 KB Output is correct
3 Correct 148 ms 17432 KB Output is correct
4 Correct 1541 ms 54560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 838 ms 34484 KB Output is correct
2 Correct 437 ms 21524 KB Output is correct
3 Correct 66 ms 16764 KB Output is correct
4 Correct 1691 ms 59192 KB Output is correct