QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190317 | #7043. Image Processing | ucup-team994 | WA | 1ms | 5640kb | C++14 | 2.1kb | 2023-09-28 17:30:47 | 2023-09-28 17:30:48 |
Judging History
answer
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
const int INF=2147483647;
const int N=1e6+5;
int n,K,last_ans,head(0),now_dp,now_diff,a[N],dp[N],pre_dp,pre_diff;
multiset<int> S_of_dp,S_of_diff;
int max(int a,int b) {
return a>=b?a:b;
}
int min(int a,int b) {
return a<=b?a:b;
}
void add_dp(int x) {
S_of_dp.insert(x);
now_dp=*S_of_dp.begin();
}
void del_dp(int x) {
auto it = S_of_dp.find(x);
if (it != S_of_dp.end()) {
S_of_dp.erase(it);
}
now_dp=*S_of_dp.begin();
}
void add_diff(int x) {
S_of_diff.insert(x);
now_diff=(*S_of_diff.rbegin())-(*S_of_diff.begin());
}
void del_diff(int x) {
auto it = S_of_diff.find(x);
if (it != S_of_diff.end()) {
S_of_diff.erase(it);
}
now_diff=(*S_of_diff.rbegin())-(*S_of_diff.begin());
}
void get_pre_dp_diff(int pos) {
if(pos!=0) {
pre_dp=min(now_dp,dp[pos-1]);
pre_diff=max(*S_of_diff.rbegin(),a[pos])-min(*S_of_diff.begin(),a[pos]);
} else {
pre_dp=pre_diff=INF;
}
return;
}
void put(int x) {
if(x>9)put(x/10);
putchar((char)(x%10+'0'));
}
int read() {
int x(0);
char ch(getchar());
while(ch>'9'||ch<'0')ch=getchar();
while(ch<='9'&&ch>='0') {
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
int main() {
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
n=read();
K=read();
for(int i=1; i<=n; i++) {
a[i]=read();
a[i]^=last_ans;
add_diff(a[i]);
if(i>=K) {
add_dp(dp[i-K]);
// if(i==21)cout<<S_of_dp.count(dp[i-K])<<'\n';
while(now_diff>=now_dp&&head<i-K) {
del_diff(a[head+1]);
del_dp(dp[head]);
head++;
}
get_pre_dp_diff(head);
last_ans=dp[i]=min(max(now_dp,now_diff),max(pre_dp,pre_diff));
if(max(now_dp,now_diff)<=max(pre_dp,pre_diff))cout<<head<<" ";
else cout<<head-1<<" ";
} else {
dp[i]=INF;
last_ans=0;
}
put(last_ans);
putchar('\n');
}
return 0;
}
/*
21 7
740760744 128949015 864430306 803157027 867410355 348411907 788815333 62537628 989888355 897434632 893725957 385915358 116671606 91645858 585889989 81062060 177182250 543069056 107482294 981936827 433021299
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5640kb
input:
5 2 50 110 190 120 34
output:
0 0 60 0 80 2 90 3 80
result:
wrong answer 2nd numbers differ - expected: '60', found: '0'