제출 #555100

#제출 시각아이디문제언어결과실행 시간메모리
555100myungwoo새로운 문제 (POI11_met)C++17
100 / 100
1691 ms59192 KiB
#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");
	}
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...