QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#182856#1848. Interval ShuffleAphroraWA 157ms14076kbC++141.5kb2023-09-18 17:20:572023-09-18 17:20:58

Judging History

This is the latest submission verdict.

  • [2023-09-18 17:20:58]
  • Judged
  • Verdict: WA
  • Time: 157ms
  • Memory: 14076kb
  • [2023-09-18 17:20:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

int n,m,li,ri;
int a[500010],tmp;
int tree[2000010],lz[2000010];

void build(int l,int r,int p) {
    if(l==r) {
        tree[p]=a[l];
        return;
    }
    int m=(l+r)>>1;
    build(l,m,p*2);
    build(m+1,r,p*2+1);
    tree[p]=max(tree[p*2],tree[p*2+1]);
}

void update(int l,int r,int s,int t,int p) {
    if(l<=s && t<=r) {
        ++lz[p];
        tree[p]=max(tree[p]+1,tmp);
        return;
    }
    int m=(s+t)>>1;
    if(lz[p]) {
        lz[p*2]+=lz[p];
        tree[p*2]=max(tree[p*2]+lz[p],tmp);
        lz[p*2+1]+=lz[p];
        tree[p*2+1]=max(tree[p*2+1]+lz[p],tmp);
        lz[p]=0;
    }
    if(l<=m) update(l,r,s,m,2*p);
	if(r>m) update(l,r,m+1,t,2*p+1);
    tree[p]=max(tree[p*2],tree[p*2+1]);
}

int getmax(int l,int r,int s,int t,int p) {
	if(l<=s && t<=r) {
		return tree[p];
	}
	int m=(t+s)>>1;
	int sum=0;
	if(lz[p]) {
		lz[p*2]+=lz[p];
        tree[p*2]=max(tree[p*2]+lz[p],tmp);
        lz[p*2+1]+=lz[p];
        tree[p*2+1]=max(tree[p*2+1]+lz[p],tmp);
        lz[p]=0;
	}
	if(l<=m) sum=max(sum,getmax(l,r,s,m,2*p));
	if(r>m) sum=max(sum,getmax(l,r,m+1,t,2*p+1));
	return sum;
}

int main() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
        scanf("%d",&a[i]);
    build(1,n,1);
    while(m--) {
        scanf("%d%d",&li,&ri);
        tmp=getmax(li,ri,1,n,1);
        update(li,ri,1,n,1);
    }
    for(int i=1;i<=n;++i)
    	printf("%d ",getmax(i,i,1,n,1));
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7888kb

input:

4 3
0 1 0 1
2 4
1 3
2 3

output:

2 4 3 2 

result:

ok 4 number(s): "2 4 3 2"

Test #2:

score: -100
Wrong Answer
time: 157ms
memory: 14076kb

input:

188394 182563
1 40 31 12 49 8 30 49 46 22 49 36 11 47 15 32 20 18 11 41 4 49 31 28 14 33 27 3 5 30 23 30 36 42 24 5 35 25 8 21 7 7 0 1 10 34 26 16 15 36 39 4 11 41 34 30 7 40 7 26 27 50 6 4 15 12 20 2 16 45 8 37 12 25 33 3 23 16 13 47 33 40 25 8 29 42 25 34 49 17 1 12 37 7 27 11 44 11 38 6 46 17 35 ...

output:

1 52588 83563 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 91837 9183...

result:

wrong answer 2nd numbers differ - expected: '49137', found: '52588'