답안 #748582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748582 2023-05-26T14:00:37 Z penguin133 Meteors (POI11_met) C++17
74 / 100
1086 ms 31292 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int q, n, m;
pii Q[300005];
int A[300005], B[300005], ans[300005], L[300005], R[300005];
vector <int> grr[300005];

int ft[300005];
void upd(int l, int r, int v){
	r++;
	for(;l<=m;l+=(l & -l))ft[l] += v;
	for(;r<=m;r+=(r & -r))ft[r] -= v;
}

int qry(int p){
	int res = 0;
	for(;p;p-=(p & -p))res += ft[p];
	return res;
}

void solve(){
	cin >> n >> m;
	for(int i=1;i<=m;i++)cin >> B[i], grr[B[i]].push_back(i);
	for(int i=1;i<=n;i++)cin >> A[i];
	cin >> q;
	for(int i=1;i<=q;i++)cin >> Q[i].fi >> Q[i].se.fi >> Q[i].se.se;
	for(int i=1;i<=n;i++)ans[i] = q + 5, L[i] = 1, R[i] = q;
	for(int i=0;i<20;i++){
		vector <pi> ord;
		for(int j = 1; j <= n; j++){
			if(L[j] > R[j])continue;
			int mid = (L[j] + R[j]) >> 1;
			ord.push_back({mid, j});
		}
		sort(ord.begin(), ord.end());
		for(int j = 1; j <= m; j++)ft[j] = 0;
		int in = 0;
		for(int j = 1; j <= q; j++){
			if(Q[j].fi <= Q[j].se.fi)upd(Q[j].fi, Q[j].se.fi, Q[j].se.se);
			else upd(Q[j].fi, m, Q[j].se.se), upd(1, Q[j].se.fi, Q[j].se.se);
			while(in < (int)ord.size() && ord[in].fi == j){
				int tmp = 0;
				for(auto k : grr[ord[in].se])tmp += qry(k);
				if(tmp >= A[ord[in].se])ans[ord[in].se] = j, R[ord[in].se] = j - 1;
				else L[ord[in].se] = j + 1;
				in++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(ans[i] <= q)cout << ans[i] << '\n';
		else cout << "NIE\n";
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

met.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7380 KB Output is correct
2 Correct 6 ms 7508 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7420 KB Output is correct
2 Correct 6 ms 7508 KB Output is correct
3 Correct 6 ms 7520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 10324 KB Output is correct
2 Correct 136 ms 13128 KB Output is correct
3 Correct 104 ms 12036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 10824 KB Output is correct
2 Correct 111 ms 11880 KB Output is correct
3 Correct 143 ms 13164 KB Output is correct
4 Correct 43 ms 10484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 10444 KB Output is correct
2 Correct 125 ms 13184 KB Output is correct
3 Correct 51 ms 9172 KB Output is correct
4 Correct 112 ms 12600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 9908 KB Output is correct
2 Correct 114 ms 11932 KB Output is correct
3 Correct 76 ms 11232 KB Output is correct
4 Correct 143 ms 13240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1086 ms 31292 KB Output is correct
2 Incorrect 725 ms 29436 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1085 ms 30404 KB Output is correct
2 Incorrect 734 ms 27860 KB Output isn't correct
3 Halted 0 ms 0 KB -