QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749975 | #9584. 顾影自怜 | BananaWolf | AC ✓ | 160ms | 56304kb | C++20 | 1.8kb | 2024-11-15 11:48:21 | 2024-11-15 11:48:25 |
Judging History
answer
//和爸爸一起学编程真好,不过要小学四年级分流考试了,最近没时间写代码了,呜呜呜
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout << #x << '=' << (x) << endl
#define out2(x, y) cout << #x << '=' << (x) << ',' << #y << '=' << (y) << endl
#define lc u<<1
#define rc u<<1|1
#define pb push_back
#define vt vector
#define fi first
#define se second
#define PII pair<int,int>
#define endl "\n"
#define il inline
typedef unsigned long long ULL;
typedef long long ll;
il int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
const int P = 13331;
const int N = 1000005;
vector<int> v[N]; //存储值域下标
int n,k;
int a[N];
ll pre[N]; //记录每个值域 离它前面最近第k个的下标
void solve(){
cin >> n >> k;
for(int i = 1;i <= n;i++) v[i].clear(),pre[i] = 0;
for(int i = 1;i <= n;i++){
cin >> a[i];
v[a[i]].pb(i);
}
for(int i = 1;i <= n;i++){
for(int j = 0;j < v[i].size();j++){
if(j-k+1<0) continue;
pre[v[i][j]] = v[i][j - k + 1];
}
}
stack<ll> st; //单调递减
ll su = 0; //当前累加和
ll ans = 0; //最后答案
a[0] = infi;
st.push(0); //虚拟最大节点,放越界
for(int i = 1;i <= n;i++){
while(!st.empty() && a[i] >= a[st.top()]){
int pretop = st.top();
st.pop();
su-=max(pre[pretop] - st.top(),0ll);
}
su+=max(0ll,pre[i] - st.top());
ans+=su;
st.push(i);
}
cout << ans << endl;
}
signed main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int times = 1;
cin >> times;
while(times--){
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7632kb
input:
2 5 2 1 3 3 2 2 4 3 1 4 2 1
output:
7 0
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 29ms
memory: 20732kb
input:
1 1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
500000500000
result:
ok single line: '500000500000'
Test #3:
score: 0
Accepted
time: 65ms
memory: 7648kb
input:
158921 1 1 1 2 1 1 1 2 2 1 1 2 1 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 3 1 1 1 1 3 2 1 1 1 3 3 1 1 1 3 1 1 1 2 3 2 1 1 2 3 3 1 1 2 3 1 1 1 3 3 2 1 1 3 3 3 1 1 3 3 1 1 2 1 3 2 1 2 1 3 3 1 2 1 3 1 1 2 2 3 2 1 2 2 3 3 1 2 2 3 1 1 2 3 3 2 1 2 3 3 3 1 2 3 3 1 1 3 1 3 2 1 3 1 3 3 1 3 1 3 1 1 3 2 3 2...
output:
1 3 1 3 0 3 0 3 1 6 3 1 6 1 0 6 1 0 6 0 0 6 2 0 6 0 0 6 0 0 6 0 0 6 2 0 6 1 0 6 1 0 6 0 0 6 2 0 6 3 1 6 1 0 6 0 0 6 0 0 6 2 0 6 1 0 6 0 0 6 1 0 6 0 0 6 1 0 6 1 0 6 2 0 6 2 0 6 3 1 10 6 3 1 10 3 1 0 10 3 1 0 10 3 1 0 10 1 0 0 10 4 0 0 10 1 0 0 10 1 0 0 10 1 0 0 10 1 0 0 10 4 0 0 10 1 0 0 10 1 0 0 10 ...
result:
ok 158921 lines
Test #4:
score: 0
Accepted
time: 45ms
memory: 19456kb
input:
1 1000000 1000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 100...
output:
498003996002
result:
ok single line: '498003996002'
Test #5:
score: 0
Accepted
time: 140ms
memory: 40320kb
input:
24 217838 1 11125 61539 156386 82530 15545 110745 20051 71328 216682 107717 24565 71482 196259 23920 79507 74383 81434 99615 50571 31499 93241 126374 205674 57290 166999 83044 89340 72667 55001 143151 30341 98608 191197 96249 176106 113045 116438 34417 92531 200248 38119 106697 24629 117110 129552 1...
output:
23726806041 1590954891 782239681 139362697540 3608208775 205782590 1992948 1449 78 2701 6 1 720 4660 34 9 91 21 1 18 3 10 1 1
result:
ok 24 lines
Test #6:
score: 0
Accepted
time: 160ms
memory: 56304kb
input:
26 946385 1 670117 545657 843923 412448 720179 557739 318687 474032 740066 816184 884900 216879 154424 237010 571714 191989 697715 453717 521834 329605 911786 112304 586798 162144 800808 303697 80404 576671 153923 684638 852686 842726 624241 934235 466016 691917 89781 33743 257181 791555 572665 1112...
output:
447822757305 14857662 13995820 5722 8260080 51681 7918210 1898855 99360 12597690 16005 2 4 1 2 1 6 2 66 1 205 6 1 3 3 1
result:
ok 26 lines
Test #7:
score: 0
Accepted
time: 45ms
memory: 12436kb
input:
200 5000 2161 4684 3947 3947 4684 3947 3947 3947 3947 3947 3947 3947 4684 3947 3947 4684 4684 3947 4684 3947 4684 3947 3947 4684 4684 3947 4684 4684 3947 4684 3947 3947 3947 4684 3947 4684 3947 4684 4684 4684 4684 3947 3947 4684 4684 3947 4684 3947 3947 4684 3947 3947 3947 3947 4684 4684 4684 4684 4...
output:
242143 9180 5417490 3741 1311390 1464616 10 954876 85078 2353898 116886 1426174 1525131 339076 1697403 1619491 298378 1017451 2189688 7230333 816003 1408681 1104841 18721 196629 183930 1648020 142311 622170 3123750 1239445 2845305 666 378 2151775 771732 53628 764466 719400 3145930 1309170 2934084 40...
result:
ok 200 lines
Test #8:
score: 0
Accepted
time: 48ms
memory: 12220kb
input:
200 5000 913 2320 1037 3761 2655 2518 3761 3761 2518 2655 2320 2320 2655 3761 2655 2655 2655 3761 1037 2518 2320 2655 3761 3761 2320 2655 2655 2655 3761 3761 2655 1037 1037 3761 2655 3761 3761 2518 1037 2655 2655 2655 1037 2655 2655 3761 2655 2518 3761 2655 2655 3761 2320 3761 1037 2655 3761 2655 10...
output:
2007353 659526 4851 1074110 7793 50721 3872 1296855 291466 1021735 4347 2116653 291546 1355481 2069595 2852466 3356688 23436 1137786 2741311 5480335 15400 190036 1276003 1371996 311655 200661 37401 2687721 1151403 288420 821121 20706 3519330 423663 1979055 2176741 2818912 2494261 2031120 935028 3685...
result:
ok 200 lines
Test #9:
score: 0
Accepted
time: 48ms
memory: 12484kb
input:
200 5000 3687 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3352 3...
output:
863955 49505 3321 2019045 846951 2716673 862641 41328 1610115 997883 886005 1809003 1433971 969528 1260078 1999000 892257 1697403 3166912 1902225 2528043 1192740 685384 1159003 597871 971514 704444 303031 1345620 2620905 2741311 1824718 2198341 1599428 2481169 2978020 713415 1396956 3104249 935664 3...
result:
ok 200 lines
Test #10:
score: 0
Accepted
time: 99ms
memory: 12080kb
input:
10 100000 2 94544 89355 27274 33773 47528 80222 15567 14092 68058 98267 50970 89136 90894 82414 59629 91287 42501 44705 74453 27333 28140 68922 9266 28406 37382 68627 93457 22625 54080 17300 70695 40013 71485 36337 10788 75135 49078 8717 59548 77850 79555 42166 59535 92722 36629 83004 16499 12040 97...
output:
2320563456 539751689 773203936 5000050000 1117001578 1806965186 1081323936 44792736 1367510297 5000050000
result:
ok 10 lines
Test #11:
score: 0
Accepted
time: 96ms
memory: 12232kb
input:
10 100000 4 81704 77987 72356 68922 238 53382 8371 95506 21026 9878 82931 19141 32961 2545 66610 70597 96816 43039 27198 53362 17443 81823 62196 93750 47184 24420 7643 58994 56301 52750 75685 36251 21471 53434 58907 76608 47452 54443 30887 13650 71405 95798 17102 22991 95147 92572 80502 79701 86329 ...
output:
544405707 63251000 5000050000 18989586 984278848 251340949 37564723 605563725 203863704 317061758
result:
ok 10 lines
Test #12:
score: 0
Accepted
time: 43ms
memory: 12484kb
input:
422 4288 1198 2132 3445 1624 2132 3445 2132 3445 1624 1624 2132 3445 3445 3445 2132 2132 2132 2132 2132 3445 2132 2132 1624 3445 2132 1624 1624 2132 2132 2132 3445 3445 3445 3445 3445 2132 2132 3445 1624 3445 3445 3445 3445 2132 2132 1624 3445 1624 2132 3445 2132 3445 1624 3445 2132 1624 3445 2132 3...
output:
485415 4005 330548 24531 3413 2016 921403 3 17205 49455 38226 1524 1 225456 194880 179182 2060517 277140 358281 709836 69751 592329 83436 229838 18721 1056331 10296 753378 8385 179104 6 1615070 1521640 155403 2543640 95703 15296 2563655 1770 17020 372031 1298466 159099 19503 57970 79704 177906 1 139...
result:
ok 422 lines
Test #13:
score: 0
Accepted
time: 40ms
memory: 12328kb
input:
412 2693 2138 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 994 99...
output:
154846 834796 1966002 196878 406 2299440 1306877 1247410 814726 4753 465 21115 163062 30135 57630 24 2063496 147153 79 317774 8385 295296 89676 114003 1570878 298378 30381 110557 100866 2089375 780 398278 936396 73536 45753 378 34260 235641 2130383 70125 1760626 2628 3486 40 9730 19110 1008825 6328 ...
result:
ok 412 lines
Test #14:
score: 0
Accepted
time: 39ms
memory: 22220kb
input:
1 999999 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
176106219446
result:
ok single line: '176106219446'
Test #15:
score: 0
Accepted
time: 37ms
memory: 20080kb
input:
1 1000000 1000000 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 714444 71...
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 65ms
memory: 46388kb
input:
1 1000000 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
250000000000
result:
ok single line: '250000000000'
Test #17:
score: 0
Accepted
time: 80ms
memory: 46776kb
input:
1 1000000 2 1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 ...
output:
500000
result:
ok single line: '500000'
Test #18:
score: 0
Accepted
time: 40ms
memory: 20448kb
input:
1 1000000 3 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 64 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 128 1 2 1 4 1 2 1 8 1 2 1 4...
output:
0
result:
ok single line: '0'
Extra Test:
score: 0
Extra Test Passed