# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421743 |
2021-06-09T11:33:22 Z |
Kerim |
Snowball (JOI21_ho_t2) |
C++17 |
|
199 ms |
9924 KB |
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll arr[MAXN],w[MAXN],par[MAXN],mx[MAXN],mn[MAXN];
PII rng[3];
const ll I=1e18;
bool intersect(PII a, PII b){
if(a.ff>b.ff)swap(a,b);
return (b.ff<=a.ss and a.ss<=b.ss);
}
PII get(int pos,int ind){
return {arr[pos]+mn[ind],arr[pos]+mx[ind]};
}
int main(){
//freopen("file.in", "r", stdin);
int n,q;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
scanf("%lld",arr+i);
arr[0]=-I;
arr[n+1]=I;
for(int i=1;i<=q;i++){
scanf("%lld",w+i);
par[i]=par[i-1]+w[i];
mn[i]=min(mn[i-1],par[i]);
mx[i]=max(mx[i-1],par[i]);
}
for(int i=1;i<=n;i++){
ll A=get(i,q).ff,B=get(i,q).ss;
if(intersect(get(i-1,q), get(i,q))){
int st=1,en=q;
while(st+1<en){
int mid=(st+en)>>1;
if(intersect(get(i-1,mid), get(i,mid)))en=mid;
else st=mid;
}
if(intersect(get(i-1,st), get(i,st)))en=st;
if(w[en]<0)A=get(i-1,en).ss;
else A=get(i,en).ff;
}
if(intersect(get(i+1,q),get(i,q))){
int st=1,en=q;
while(st+1<en){
int mid=(st+en)>>1;
if(intersect(get(i+1,mid),get(i,mid)))en=mid;
else st=mid;
}
if(intersect(get(i+1,st),get(i,st)))en=st;
if(w[en]<0)B=get(i,en).ss;
else B=get(i+1,en).ff;
}
printf("%lld\n",B-A);
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%lld",arr+i);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%lld",w+i);
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
34 ms |
6464 KB |
Output is correct |
21 |
Correct |
35 ms |
6576 KB |
Output is correct |
22 |
Correct |
33 ms |
6512 KB |
Output is correct |
23 |
Correct |
32 ms |
6448 KB |
Output is correct |
24 |
Correct |
43 ms |
6848 KB |
Output is correct |
25 |
Correct |
172 ms |
9632 KB |
Output is correct |
26 |
Correct |
174 ms |
9656 KB |
Output is correct |
27 |
Correct |
166 ms |
9388 KB |
Output is correct |
28 |
Correct |
171 ms |
9424 KB |
Output is correct |
29 |
Correct |
172 ms |
9196 KB |
Output is correct |
30 |
Correct |
199 ms |
8772 KB |
Output is correct |
31 |
Correct |
105 ms |
8396 KB |
Output is correct |
32 |
Correct |
90 ms |
8388 KB |
Output is correct |
33 |
Correct |
15 ms |
1284 KB |
Output is correct |
34 |
Correct |
168 ms |
9660 KB |
Output is correct |
35 |
Correct |
178 ms |
9468 KB |
Output is correct |
36 |
Correct |
169 ms |
9624 KB |
Output is correct |
37 |
Correct |
176 ms |
9460 KB |
Output is correct |
38 |
Correct |
174 ms |
9460 KB |
Output is correct |
39 |
Correct |
154 ms |
9412 KB |
Output is correct |
40 |
Correct |
119 ms |
9416 KB |
Output is correct |
41 |
Correct |
36 ms |
6468 KB |
Output is correct |
42 |
Correct |
71 ms |
8516 KB |
Output is correct |
43 |
Correct |
103 ms |
9796 KB |
Output is correct |
44 |
Correct |
38 ms |
6596 KB |
Output is correct |
45 |
Correct |
83 ms |
9592 KB |
Output is correct |
46 |
Correct |
104 ms |
9924 KB |
Output is correct |
47 |
Correct |
114 ms |
9916 KB |
Output is correct |
48 |
Correct |
107 ms |
9924 KB |
Output is correct |