# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
942080 |
2024-03-10T08:26:03 Z |
dsyz |
Snowball (JOI21_ho_t2) |
C++17 |
|
2500 ms |
4024 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,Q;
cin>>N>>Q;
set<pair<ll,ll> > s; //stores ranges of 1s
s.insert({-1e18,1e18});
ll X[N];
for(ll i = 0;i < N;i++){
cin>>X[i];
}
ll ans[N];
memset(ans,0,sizeof(ans));
ll wind[Q];
for(ll q = 0;q < Q;q++){
cin>>wind[q];
if(wind[q] > 0){ //blow right
for(ll i = N - 1;i >= 0;i--){
ll Lb = X[i], Rb = X[i] + wind[q] - 1;
auto it = s.lower_bound({Lb,Rb});
if(it != s.begin()){
auto it2 = it;
it2--;
if(it2->second >= Rb){
pair<ll,ll> tmp = *it2;
s.erase(it2);
if(tmp.first < Lb) s.insert({tmp.first,Lb - 1});
if(Rb < tmp.second) s.insert({Rb + 1,tmp.second});
ans[i] += (Rb - Lb + 1);
}else if(it2->second >= Lb){
pair<ll,ll> tmp = *it2;
s.erase(it2);
s.insert({tmp.first,Lb - 1});
ans[i] += (tmp.second - Lb + 1);
}
}
while(it != s.end() && it->first <= Rb){
pair<ll,ll> tmp = *it;
ans[i] += (min(Rb,it->second) - max(Lb,it->first) + 1);
auto it2 = it;
it++;
s.erase(it2);
if(tmp.first < Lb) s.insert({tmp.first,Lb - 1});
if(tmp.second > Rb) s.insert({Rb + 1,tmp.second});
}
X[i] += wind[q];
}
}else if(wind[q] < 0){ //blow left
wind[q] *= -1;
for(ll i = 0;i < N;i++){
ll Lb = X[i] - wind[q], Rb = X[i] - 1;
auto it = s.lower_bound({Lb,Rb});
if(it != s.begin()){
auto it2 = it;
it2--;
if(it2->second >= Rb){
pair<ll,ll> tmp = *it2;
s.erase(it2);
if(tmp.first < Lb) s.insert({tmp.first,Lb - 1});
if(Rb < tmp.second) s.insert({Rb + 1,tmp.second});
ans[i] += (Rb - Lb + 1);
}else if(it2->second >= Lb){
pair<ll,ll> tmp = *it2;
s.erase(it2);
s.insert({tmp.first,Lb - 1});
ans[i] += (tmp.second - Lb + 1);
}
}
while(it != s.end() && it->first <= Rb){
pair<ll,ll> tmp = *it;
ans[i] += (min(Rb,it->second) - max(Lb,it->first) + 1);
auto it2 = it;
it++;
s.erase(it2);
if(tmp.first < Lb) s.insert({tmp.first,Lb - 1});
if(tmp.second > Rb) s.insert({Rb + 1,tmp.second});
}
X[i] -= wind[q];
}
}
}
for(ll i = 0;i < N;i++){
cout<<ans[i]<<'\n';
}
cout<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
23 ms |
480 KB |
Output is correct |
4 |
Correct |
301 ms |
604 KB |
Output is correct |
5 |
Correct |
293 ms |
640 KB |
Output is correct |
6 |
Correct |
304 ms |
636 KB |
Output is correct |
7 |
Correct |
325 ms |
604 KB |
Output is correct |
8 |
Correct |
287 ms |
636 KB |
Output is correct |
9 |
Correct |
172 ms |
604 KB |
Output is correct |
10 |
Correct |
75 ms |
804 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
299 ms |
648 KB |
Output is correct |
16 |
Correct |
298 ms |
604 KB |
Output is correct |
17 |
Correct |
228 ms |
640 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
23 ms |
480 KB |
Output is correct |
4 |
Correct |
301 ms |
604 KB |
Output is correct |
5 |
Correct |
293 ms |
640 KB |
Output is correct |
6 |
Correct |
304 ms |
636 KB |
Output is correct |
7 |
Correct |
325 ms |
604 KB |
Output is correct |
8 |
Correct |
287 ms |
636 KB |
Output is correct |
9 |
Correct |
172 ms |
604 KB |
Output is correct |
10 |
Correct |
75 ms |
804 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
299 ms |
648 KB |
Output is correct |
16 |
Correct |
298 ms |
604 KB |
Output is correct |
17 |
Correct |
228 ms |
640 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
42 ms |
4024 KB |
Output is correct |
21 |
Correct |
170 ms |
3892 KB |
Output is correct |
22 |
Correct |
2065 ms |
3652 KB |
Output is correct |
23 |
Execution timed out |
2574 ms |
2252 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |