QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#865191 | #894. Longest Loose Segment | yinhee | WA | 702ms | 47284kb | C++17 | 1.9kb | 2025-01-21 15:55:12 | 2025-01-21 15:55:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define mems(x,y) memset(x,y,sizeof x)
#define Mp make_pair
#define eb emplace_back
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define il inline
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a);i>=(b);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
il void read(T &x){
int f=1;x=0;char c=gc();
while(c<'0'||c>'9'){
if(c=='-'){
f=-1;
}
c=gc();
}
while(c>='0'&&c<='9'){
x=x*10+c-48,c=gc();
}
x*=f;
}
template<typename T,typename ...Args>
void read(T &x,Args &...args){
read(x),read(args...);
}
template<typename T>
il void write(T x){
char buf[43];int len=0;
if(x<0){
pc('-'),x=-x;
}
do{
buf[++len]=x%10,x/=10;
}while(x);
while(len){
pc(buf[len--]+'0');
}
}
}
using namespace my_std;
const int N=1e6+7,M=-1,inf=0x3f3f3f3f,mod=0;
int n,q,top,a[N],st[N],ls[N],rs[N],f[N],siz[N],dp[N];
void dfs(int u){
if(!u){
return;
}
dfs(ls[u]),dfs(rs[u]);
siz[u]=siz[ls[u]]+siz[rs[u]]+1;
f[u]=max({f[ls[u]],f[rs[u]],a[u]});
dp[u]=max(dp[ls[u]],dp[rs[u]]);
if(f[ls[u]]+a[u]>siz[ls[u]]+1){
dp[u]=max(dp[u],min(f[ls[u]]+a[u],siz[u]));
}
if(f[rs[u]]+a[u]>siz[rs[u]]+1){
dp[u]=max(dp[u],min(f[rs[u]]+a[u],siz[u]));
}
}
void solve(){
top=0;
rep(i,1,n){
ls[i]=rs[i]=0;
while(top&&a[st[top]]>a[i]){
ls[i]=st[top--];
}
if(top){
rs[st[top]]=i;
}
st[++top]=i;
}
f[0]=-inf,dfs(st[1]);
printf("%d\n",dp[st[1]]);
}
void Yorushika(){
read(n,q);
rep(i,1,n){
read(a[i]);
}
solve();
while(q--){
int m;read(m);
while(m--){
int x,y;read(x,y);
swap(a[x],a[y]);
}
solve();
}
}
signed main(){
int t=1;
//read(t);
while(t--){
Yorushika();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 14028kb
input:
5 2 1 2 -2 3 4 1 2 3 1 1 2
output:
2 3 4
result:
ok 3 tokens
Test #2:
score: -100
Wrong Answer
time: 702ms
memory: 47284kb
input:
998546 30 998544 998544 998543 998539 998538 998537 998536 998534 998533 998531 998529 998527 998522 998521 998520 998520 998516 998514 998512 998509 998501 998501 998500 998499 998498 998496 998494 998493 998491 998491 998490 998489 998489 998488 998488 998486 998483 998480 998479 998478 998475 998...
output:
212115 16719 12587 9069 8112 7079 7404 7404 5937 5941 5847 5759 6492 5465 5465 5565 5565 5408 5408 5669 5669 5408 6263 6351 6351 5326 4609 4613 4613 4430 4613
result:
wrong answer 1st words differ - expected: '212114', found: '212115'