# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1104928 |
2024-10-24T18:06:50 Z |
Irate |
Meteors (POI11_met) |
C++17 |
|
2829 ms |
57792 KB |
#include<bits/stdc++.h>
using namespace std;
const int LOG = 20;
struct Query{
int l, r, a;
};
struct T{
int l, r, ans = -1;
};
struct BIT{
vector<long long>fen;
int sz;
BIT(int n){
sz = n;
fen.resize(n + 1);
}
void Update(int pos, int val){
while(pos <= sz){
fen[pos] += val;
pos += (pos & -pos);
}
}
long long Sum(int pos){
long long sum = 0;
while(pos > 0){
sum += fen[pos];
pos -= (pos & -pos);
}
return sum;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> m >> n;
vector<int>v(n + 1), need(m + 1);
vector<vector<int>>pos(m + 1);
vector<T>intervals(m + 1);
for(int i = 1;i <= n;++i){
cin >> v[i];
pos[v[i]].push_back(i);
}
for(int i = 1;i <= m;++i){
cin >> need[i];
}
int q;
cin >> q;
vector<vector<int>>timeline(q);
vector<Query>queries(q);
for(int i = 1;i <= m;++i){
timeline[(q - 1) / 2].push_back(i);
intervals[i] = {0, q - 1};
}
for(int i = 0;i < q;++i){
int l, r, a;
cin >> l >> r >> a;
queries[i] = {l, r, a};
}
BIT tree(n + 1);
for(int i = 0;i < LOG;++i){
for(int j = 0;j < q;++j){
int l = queries[j].l, r = queries[j].r, a = queries[j].a;
if(l <= r){
tree.Update(l, a);
tree.Update(r + 1, -a);
}
else{
tree.Update(l, a);
tree.Update(1, a);
tree.Update(r + 1, -a);
}
while(!timeline[j].empty()){
int base = timeline[j].back();
timeline[j].pop_back();
l = intervals[base].l, r = intervals[base].r;
int ans = intervals[base].ans;
long long tot = 0;
for(int &p : pos[base]){
tot += tree.Sum(p);
if(tot >= need[base]){
break;
}
}
if(tot >= need[base]){
intervals[base] = {l, (l + r) / 2 - 1, (l + r) / 2};
}
else{
intervals[base] = {(l + r) / 2 + 1, r, ans};
}
}
}
for(int j = 1;j <= m;++j){
timeline[(intervals[j].l + intervals[j].r) / 2].push_back(j);
}
for(int j = 0;j < q;++j){
int l = queries[j].l, r = queries[j].r, a = queries[j].a;
if(l <= r){
tree.Update(l, -a);
tree.Update(r + 1, a);
}
else{
tree.Update(l, -a);
tree.Update(1, -a);
tree.Update(r + 1, a);
}
}
}
for(int i = 1;i <= m;++i){
int ans = intervals[i].ans;
if(ans < 0){
cout << "NIE\n";
}
else{
cout << ans + 1 << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
3524 KB |
Output is correct |
2 |
Correct |
178 ms |
6216 KB |
Output is correct |
3 |
Correct |
120 ms |
5384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
4680 KB |
Output is correct |
2 |
Correct |
148 ms |
4940 KB |
Output is correct |
3 |
Correct |
174 ms |
6216 KB |
Output is correct |
4 |
Correct |
32 ms |
3408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
4164 KB |
Output is correct |
2 |
Correct |
123 ms |
6728 KB |
Output is correct |
3 |
Correct |
65 ms |
2128 KB |
Output is correct |
4 |
Correct |
131 ms |
5996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
3144 KB |
Output is correct |
2 |
Correct |
160 ms |
4936 KB |
Output is correct |
3 |
Correct |
91 ms |
3280 KB |
Output is correct |
4 |
Correct |
163 ms |
7496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2083 ms |
30668 KB |
Output is correct |
2 |
Correct |
1565 ms |
15684 KB |
Output is correct |
3 |
Correct |
305 ms |
9296 KB |
Output is correct |
4 |
Correct |
2695 ms |
53080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2136 ms |
28992 KB |
Output is correct |
2 |
Correct |
1589 ms |
15812 KB |
Output is correct |
3 |
Correct |
265 ms |
7540 KB |
Output is correct |
4 |
Correct |
2829 ms |
57792 KB |
Output is correct |