# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
491712 |
2021-12-03T22:46:01 Z |
faresbasbs |
Meteors (POI11_met) |
C++14 |
|
4971 ms |
53836 KB |
#include <bits/stdc++.h>
using namespace std;
struct p{
long long l1,r1,l2,r2,val;
};
const int sq = sqrt(300001);
long long n,m,k,t,type[300001],val[300001],sum[300001];
pair<long long,long long> lst[300001];
vector<long long> segment,all[300001];
bool done[300001];
p event[300001];
void upd(int a , int b , int v , int curr , int l , int r){
if(b < l || a > r){
return ;
}
if(a <= l && b >= r){
segment[curr] += v;
return ;
}
int mid = (l+r)/2;
upd(a,b,v,2*curr,l,mid),upd(a,b,v,2*curr+1,mid+1,r);
}
long long getsum(int idx){
idx += t-1;
long long ret = 0;
while(idx){
ret += segment[idx];
idx /= 2;
}
return ret;
}
long long num(int l , int r , int idx){
return (upper_bound(all[idx].begin(),all[idx].end(),r)-all[idx].begin())-(lower_bound(all[idx].begin(),all[idx].end(),l)-all[idx].begin());
}
long long getval(int idx , int ev){
long long numb = num(event[ev].l1,event[ev].r1,idx)+(event[ev].l2 == -1 ? 0ll : num(event[ev].l2,event[ev].r2,idx));
return event[ev].val*numb;
}
void check(int idx){
for(int i = 1 ; i <= n ; i += 1){
sum[i] = 0;
}
for(int i = 1 ; i <= m ; i += 1){
if(done[type[i]]){
continue;
}
sum[type[i]] += getsum(i);
}
for(int i = 1 ; i <= n ; i += 1){
if(sum[i] >= val[i]){
done[i] = 1;
}
if(done[i]){
continue;
}
lst[i] = {sum[i],idx};
}
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
cin >> n >> m;
t = pow(2,ceil(log2(m)));
segment.resize(2*t,0);
for(int i = 1 ; i <= m ; i += 1){
cin >> type[i];
all[type[i]].push_back(i);
}
for(int i = 1 ; i <= n ; i += 1){
cin >> val[i];
lst[i] = {0,0};
}
cin >> k;
for(int i = 1 ; i <= k ; i += 1){
int l,r,v;
cin >> l >> r >> v;
if(r >= l){
event[i] = {l,r,-1,-1,v};
upd(l,r,v,1,1,t);
}else{
event[i] = {l,m,1,r,v};
upd(l,m,v,1,1,t),upd(1,r,v,1,1,t);
}
if(i%sq == 0){
check(i);
}
}
check(m);
for(int i = 1 ; i <= n ; i += 1){
if(!done[i]){
cout << "NIE\n";
continue;
}
pair<long long,long long> curr = lst[i];
while(curr.first < val[i]){
curr.second += 1;
curr.first += getval(i,curr.second);
}
cout << curr.second << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
5 ms |
7500 KB |
Output is correct |
3 |
Correct |
8 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
9 ms |
7500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11440 KB |
Output is correct |
2 |
Correct |
127 ms |
12520 KB |
Output is correct |
3 |
Correct |
168 ms |
12024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
11760 KB |
Output is correct |
2 |
Correct |
136 ms |
11760 KB |
Output is correct |
3 |
Correct |
89 ms |
12424 KB |
Output is correct |
4 |
Correct |
39 ms |
10308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
11532 KB |
Output is correct |
2 |
Correct |
135 ms |
12372 KB |
Output is correct |
3 |
Correct |
30 ms |
9356 KB |
Output is correct |
4 |
Correct |
150 ms |
13252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11236 KB |
Output is correct |
2 |
Correct |
105 ms |
11784 KB |
Output is correct |
3 |
Correct |
128 ms |
11444 KB |
Output is correct |
4 |
Correct |
209 ms |
12548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4971 ms |
38856 KB |
Output is correct |
2 |
Correct |
335 ms |
39912 KB |
Output is correct |
3 |
Correct |
105 ms |
19484 KB |
Output is correct |
4 |
Correct |
4640 ms |
51688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4595 ms |
38044 KB |
Output is correct |
2 |
Correct |
1355 ms |
38680 KB |
Output is correct |
3 |
Correct |
86 ms |
18628 KB |
Output is correct |
4 |
Correct |
4542 ms |
53836 KB |
Output is correct |