Submission #748587

# Submission time Handle Problem Language Result Execution time Memory
748587 2023-05-26T14:05:55 Z penguin133 Meteors (POI11_met) C++17
100 / 100
2031 ms 49892 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){
				__int128 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(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7380 KB Output is correct
2 Correct 7 ms 7508 KB Output is correct
3 Correct 6 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 8 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 10312 KB Output is correct
2 Correct 124 ms 11928 KB Output is correct
3 Correct 113 ms 11108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 10808 KB Output is correct
2 Correct 108 ms 10784 KB Output is correct
3 Correct 145 ms 12072 KB Output is correct
4 Correct 43 ms 10088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 10428 KB Output is correct
2 Correct 141 ms 11880 KB Output is correct
3 Correct 49 ms 8548 KB Output is correct
4 Correct 113 ms 11472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 9908 KB Output is correct
2 Correct 112 ms 10724 KB Output is correct
3 Correct 76 ms 10072 KB Output is correct
4 Correct 147 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1120 ms 31160 KB Output is correct
2 Correct 756 ms 21660 KB Output is correct
3 Correct 239 ms 15672 KB Output is correct
4 Correct 1836 ms 47436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1139 ms 30384 KB Output is correct
2 Correct 736 ms 21624 KB Output is correct
3 Correct 214 ms 15488 KB Output is correct
4 Correct 2031 ms 49892 KB Output is correct