QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#840404 | #8712. Flooding Wall | devvops# | 0 | 1ms | 5888kb | C++20 | 3.9kb | 2025-01-02 18:15:24 | 2025-01-02 18:15:25 |
Judging History
answer
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <complex>
#include <climits>
#include <random>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
#define ll long long
const int mod = (int) 1e9 + 7;
int add(int x, int y){
ll s = 0LL + x + y;
if(s >= mod) s -= mod;
if(s < 0) s += mod;
return s;
}
int sub(int x, int y){
return add(x, -y);
}
int mul(int x, int y){
ll s = 1LL * x * y;
return (s % mod);
}
int n;
ll a[500005][2];
ll step[500005];
ll suf[10005][5];
ll pref[10005][5];
void sub1234(){
ll ans = 0;
set<int> d;
for(int i = 0; i < n; i++){
for(int j = 0; j <= 1; j++){
d.insert(a[i][j]);
}
}
for(auto x : d){
pref[0][0] = 1;
pref[0][1] = pref[0][2] = 0;
for(int i = 0; i < n; i++){
pref[i + 1][0] = pref[i + 1][1] = pref[i + 1][2] = 0;
for(int j = 0; j <= 1; j++){
if(a[i][j] < x){
pref[i + 1][0] += pref[i][0];
pref[i + 1][1] += pref[i][1];
pref[i + 1][2] += pref[i][2];
}
else if(a[i][j] == x){
pref[i + 1][1] += pref[i][0];
pref[i + 1][1] += pref[i][1];
pref[i + 1][2] += pref[i][2];
}
else{
pref[i + 1][2] += (pref[i][0] + pref[i][1] + pref[i][2]);
}
for(int k = 0; k < 3; k++) pref[i + 1][k] %= mod;
}
}
suf[n][0] = 1;
suf[n][1] = suf[n][2] = 0;
for(int i = n - 1; i >= 0; i--){
suf[i][0] = suf[i][1] = suf[i][2] = 0;
for(int j = 0; j <= 1; j++){
if(a[i][j] < x){
suf[i][0] += suf[i + 1][0];
suf[i][1] += suf[i + 1][1];
suf[i][2] += suf[i + 1][2];
}
else if(a[i][j] == x){
suf[i][1] += suf[i + 1][0];
suf[i][1] += suf[i + 1][1];
suf[i][2] += suf[i + 1][2];
}
else{
suf[i][2] += (suf[i + 1][0] + suf[i + 1][1] + suf[i + 1][2]);
}
for(int k = 0; k < 3; k++) suf[i][k] %= mod;
}
}
ll add = 0;
for(int i = 1; i < n - 1; i++){
int c = (pref[i][1] * suf[i + 1][1] + pref[i][2] * suf[i + 1][1] + pref[i][1] * suf[i + 1][2]) % mod;
int total = max(0LL, x - a[i][0]) + max(0LL, x - a[i][1]);
add = (add + (c * total) % mod) % mod;
}
ans = (ans + add) % mod;
}
cout << ans;
}
void sub5(){
step[0] = 1;
int ans = 0;
for(int i = 2; i <= n - 1; i++){
int kek = sub(sub(sub(step[n - 1], sub(step[i - 1], 1)), sub(step[n - i], 1)), 1);
ans = add(ans, kek);
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
step[i] = (1LL * step[i - 1] * 2) % mod;
}
bool s5 = 1;
for(int k = 0; k <= 1; k++){
for(int i = 0; i < n; i++){
cin >> a[i][k];
s5 &= (a[i][k] <= 2);
}
}
/*
if(s5){
sub5();
return 0;
}
*/
sub1234();
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 1ms
memory: 5812kb
input:
4 1 1 1 1 2 2 2 2
output:
6
result:
ok single line: '6'
Test #2:
score: 8
Accepted
time: 1ms
memory: 5600kb
input:
10 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
output:
21116
result:
ok single line: '21116'
Test #3:
score: 8
Accepted
time: 1ms
memory: 5612kb
input:
1 1 2
output:
0
result:
ok single line: '0'
Test #4:
score: 8
Accepted
time: 1ms
memory: 5884kb
input:
2 1 1 2 2
output:
0
result:
ok single line: '0'
Test #5:
score: 8
Accepted
time: 1ms
memory: 5884kb
input:
3 1 1 1 2 2 2
output:
1
result:
ok single line: '1'
Test #6:
score: 8
Accepted
time: 1ms
memory: 5644kb
input:
3 1 1 1 3 2 3
output:
3
result:
ok single line: '3'
Test #7:
score: 8
Accepted
time: 1ms
memory: 5596kb
input:
3 2 1 1 3 2 3
output:
4
result:
ok single line: '4'
Test #8:
score: 8
Accepted
time: 1ms
memory: 5812kb
input:
3 1 1 2 3 2 3
output:
4
result:
ok single line: '4'
Test #9:
score: 8
Accepted
time: 1ms
memory: 5668kb
input:
4 1 1 2 2 2 2 1 1
output:
6
result:
ok single line: '6'
Test #10:
score: 8
Accepted
time: 1ms
memory: 5868kb
input:
3 1 4 4 3 1 1
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Wrong Answer
time: 1ms
memory: 5608kb
input:
20 801072306 297281669 94099424 745640358 822582129 579751930 776707816 425952653 529794053 256263083 615445445 401366545 990263003 967996508 788867983 916880116 837997768 346996508 623409388 122077161 141734988 448434751 822901346 825591177 388082644 468025968 260356829 1164654 537396602 730502935 ...
output:
-563989788
result:
wrong answer 1st lines differ - expected: '840988190', found: '-563989788'
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 1ms
memory: 5888kb
input:
100 948 425 211 688 416 81 356 602 712 954 117 522 797 75 281 491 662 669 78 156 939 526 929 937 916 619 166 777 48 898 449 278 298 714 668 755 679 38 389 602 195 135 672 833 655 541 473 27 596 274 351 353 598 993 837 246 950 99 179 751 481 843 550 195 964 279 806 82 330 599 124 756 649 838 513 625 ...
output:
634462879
result:
wrong answer 1st lines differ - expected: '164439470', found: '634462879'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Runtime Error
Test #57:
score: 0
Runtime Error
input:
500000 1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 2 1 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 1 2 2 1 1 2 1 2 1...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
0%