Submission #605625

# Submission time Handle Problem Language Result Execution time Memory
605625 2022-07-25T20:05:57 Z 1ne Meteors (POI11_met) C++14
100 / 100
1516 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
struct node{
	long long l,r,v;
};
const int maxn = 300005;
long long tree[maxn];
int m;
void update(int x, long long val){
	while(x<=m){
		tree[x]+=val;
		x+=(x&-x);
 
	}
}
long long read(int x){
	long long s=0;
	while(x>0){
		s+=tree[x];
		x-=(x&-x);
	}
	return s;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;cin>>n>>m;
	vector<vector<int>>arr(n);
	for (int i = 0;i<m;++i){
		int x;cin>>x;
		arr[x - 1].push_back(i);
	}
	vector<long long>brr(n);
	for (int i = 0;i<n;++i)cin>>brr[i];
	int k;cin>>k;
	vector<node>edge(k);
	for (int i = 0;i<k;++i){
		cin>>edge[i].l>>edge[i].r>>edge[i].v;
		edge[i].l--;
		edge[i].r--;
	}
	queue<node>q;
	vector<int>l(n),r(n);
	for (int i = 0;i<n;++i){
		l[i] = 0,r[i] = k;
	}
	vector<int>ans(n,-1);
	bool changed = true;
	vector<vector<int>>need(k + 1);
	for (int i = 0;i<n;++i){
		int mid = (l[i] + r[i])>>1;
		if (l[i] >= r[i]){
			ans[i] = l[i];
		}
		else{
			need[mid].push_back(i);
		}
	}
	while(changed){
		changed = false;
		for (int i = 0;i<=m;++i)tree[i] = 0;
		for (int i = 0;i<k;++i){
			if (edge[i].l<=edge[i].r){
				update(edge[i].l + 1,edge[i].v),update(edge[i].r + 2,-edge[i].v);
			}
			else{
				update(1,edge[i].v);
				update(edge[i].r + 2,-edge[i].v);
				update(edge[i].l + 1,edge[i].v);
			}
			while(!need[i].empty()){
				int x = need[i].back();
				need[i].pop_back();
				changed = true;
				long long sum = 0;
				for (auto y:arr[x]){
					sum+=read(y + 1);
					if (sum >= brr[x])break;
				}
				if (sum < brr[x]){
					l[x] = i + 1;
				}
				else{
					r[x] = i;
				}
				if (l[x] >= r[x]){
					ans[x] = l[x];
				}
				else{
					need[(l[x] + r[x])>>1].push_back(x);
				}
			}
		}
	}
	for (auto x:ans){
		x++;
		if (x > k)cout<<"NIE\n";
		else cout<<x<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 4036 KB Output is correct
2 Correct 97 ms 6476 KB Output is correct
3 Correct 80 ms 5772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 5148 KB Output is correct
2 Correct 80 ms 5140 KB Output is correct
3 Correct 92 ms 6680 KB Output is correct
4 Correct 24 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4428 KB Output is correct
2 Correct 88 ms 7152 KB Output is correct
3 Correct 37 ms 2816 KB Output is correct
4 Correct 81 ms 6384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 3388 KB Output is correct
2 Correct 82 ms 5196 KB Output is correct
3 Correct 64 ms 3664 KB Output is correct
4 Correct 109 ms 7900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 625 ms 33272 KB Output is correct
2 Correct 590 ms 18156 KB Output is correct
3 Correct 191 ms 12232 KB Output is correct
4 Correct 1364 ms 55880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 663 ms 31620 KB Output is correct
2 Correct 565 ms 18064 KB Output is correct
3 Correct 187 ms 9776 KB Output is correct
4 Correct 1516 ms 65536 KB Output is correct