QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749964 | #9584. 顾影自怜 | BananaWolf | WA | 67ms | 22080kb | C++20 | 1.8kb | 2024-11-15 11:44:11 | 2024-11-15 11:44:12 |
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();
if(pre[pretop] > st.top()) su=0;
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7624kb
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: 39ms
memory: 22080kb
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: -100
Wrong Answer
time: 67ms
memory: 7916kb
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 5 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 5 1 0 5 0 0 6 1 0 6 0 0 5 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:
wrong answer 37th lines differ - expected: '6', found: '5'