Submission #347777

# Submission time Handle Problem Language Result Execution time Memory
347777 2021-01-13T12:03:57 Z lovro_nidogon1 Meteors (POI11_met) C++14
100 / 100
5999 ms 57056 KB
#include<bits/stdc++.h>
#define breturn return
#define ll long long
using namespace std;
const int maxn = 300001;
ll n, m, o[maxn], p[maxn], a, b, c, q, bn, tour[1048600], ans[maxn]; 
vector<pair<ll, pair<ll, ll> > > midl[maxn], quer;
vector<ll> v[maxn];
bool done; 
void upd(ll ax, ll bx, ll val, ll x = 1, ll l = 0, ll r = bn - 1) {	
	if(ax > r or bx < l) breturn;
	if(l >= ax and r <= bx) {
		tour[x] += val;
		breturn;
	} 
	ll mid = (l + r)/2;
	upd(ax, bx, val, x * 2, l, mid);
	upd(ax, bx, val, x * 2 + 1, mid + 1, r);
}
ll query(ll ax, ll bx, ll x = 1, ll l = 0, ll r = bn - 1) {
	if(ax > r or bx < l) breturn 0;;
	if(l >= ax and r <= bx) breturn tour[x];	 
	tour[x * 2] += tour[x];
	tour[x * 2 + 1] += tour[x];
	tour[x] = 0;
	ll mid = (l + r)/2;
	breturn query(ax, bx, x * 2, l, mid) + query(ax, bx, x * 2 + 1, mid + 1, r);
}
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++ ) cin >> a, v[a - 1].push_back(i);
	for(ll i = 0; i < n; i++) cin >> p[i];	
	cin >> q;
	bn = (1 << ((ll)log2(m - 1 + (m == 1)) + 1));
	for(ll i = 0; i < q; i++) {
		cin >> a >> b >> c;
		quer.push_back({c, {a - 1, b - 1}});		
	}
	for(ll i = 0; i < n; i++) midl[(int)(q/2)].push_back({i, {0, q}});
	while(!done) {
		done = true;
		for(ll i = 0; i < 2 * bn; i++) tour[i] = 0;
		for(ll i = 0; i < q; i++) {
			if(quer[i].second.first > quer[i].second.second) {
				upd(0, quer[i].second.second, quer[i].first);
				upd(quer[i].second.first, m - 1, quer[i].first);
			} else upd(quer[i].second.first, quer[i].second.second, quer[i].first);			
			for(ll j = 0; j < midl[i].size(); j++) {				
				ll y = midl[i][j].first;
				ll x = 0;
				for(ll k = 0; k < v[y].size() and x < p[y]; k++) x += query(v[y][k], v[y][k]);														
				ll le = midl[i][j].second.first;
				ll re = midl[i][j].second.second;
				ll mid = (le + re)/2;
				if(x < p[y]) le = mid + 1;
				else re = mid;				
				mid = (le + re)/2;
				if(le == re) ans[y] = le;
				else midl[mid].push_back({y, {le, re}}), done = false;													
			}
			midl[i].clear();		
			midl[i].shrink_to_fit();
		}
	}
	for(ll i = 0; i < n; i++) {
		if(ans[i] == q) cout << "NIE\n";
		else cout << ans[i] + 1 << '\n';
	}
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:49:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    for(ll j = 0; j < midl[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~~~~
met.cpp:52:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(ll k = 0; k < v[y].size() and x < p[y]; k++) x += query(v[y][k], v[y][k]);
      |                   ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14572 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14572 KB Output is correct
2 Correct 12 ms 14592 KB Output is correct
3 Correct 14 ms 14572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 17900 KB Output is correct
2 Correct 521 ms 20448 KB Output is correct
3 Correct 486 ms 18656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 471 ms 18532 KB Output is correct
2 Correct 469 ms 18412 KB Output is correct
3 Correct 502 ms 20192 KB Output is correct
4 Correct 139 ms 17588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 247 ms 18016 KB Output is correct
2 Correct 356 ms 19940 KB Output is correct
3 Correct 164 ms 16100 KB Output is correct
4 Correct 446 ms 19044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 17372 KB Output is correct
2 Correct 414 ms 18332 KB Output is correct
3 Correct 396 ms 17640 KB Output is correct
4 Correct 509 ms 20192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3723 ms 44996 KB Output is correct
2 Correct 1655 ms 32864 KB Output is correct
3 Correct 879 ms 20700 KB Output is correct
4 Correct 5999 ms 55184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3985 ms 45748 KB Output is correct
2 Correct 1287 ms 32896 KB Output is correct
3 Correct 790 ms 20700 KB Output is correct
4 Correct 5412 ms 57056 KB Output is correct