#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
int mod=1e9+7;
int f(int a, int b){
a%=mod;
b%=mod;
return (a*b)%mod;
}
int calc(int n){
int hold=f(f(n,n+1),500000004);
return hold;
}
int len(int a, int b){
return b-a+1;
}
void solve(){
int n;
cin >> n;
pii arr[n];
for(int x=0;x<n;x++){
cin >> arr[x].first;
}
for(int x=0;x<n;x++){
cin >> arr[x].second;
}
int last=-1;
int counter=0;
int pos=1;
for(int x=0;x<n;x++){
if(arr[x].first==1){
counter=(counter+calc(len(1,pos+arr[x].second-1))-calc(len(1,pos-1))+mod)%mod;
last=-1;
}
else if(arr[x].first==2){
if(last==-1) last=pos;
int hold=calc(len(last,pos+arr[x].second-1))-calc(len(last,pos-1));
hold=(hold+mod)%mod;
counter=(counter+2*hold)%mod;
counter=(counter+calc(len(1,pos+arr[x].second-1))-calc(len(1,pos-1))+mod)%mod;
}
//show(counter,counter);
pos+=arr[x].second;
}
cout << counter;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("redistricting.in", "r", stdin);
//freopen("redistricting.out", "w", stdout);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
11 ms |
1624 KB |
Output is correct |
4 |
Correct |
20 ms |
3164 KB |
Output is correct |
5 |
Correct |
22 ms |
3164 KB |
Output is correct |
6 |
Correct |
24 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |