QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#22340#2356. Partition of Querieshy_zheng_zai_nei_juan#WA 16ms36844kbC++203.4kb2022-03-09 15:37:062022-04-30 00:55:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 00:55:08]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:36844kb
  • [2022-03-09 15:37:06]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
    #define BUF_SIZE 100000
    bool IOerror=0;
    inline char nc()
	{
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline ll read()
	{
        bool sign=0; char ch=nc();ll x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return 0;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
        return x;
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int s[1000010];
int ck[4000010],cb[4000010],col[4000010],mn[4000010],mx[4000010];
void pushup(int x){mx[x]=max(mx[x<<1],mx[x<<1|1]),mn[x]=min(mn[x<<1],mn[x<<1|1]);}
void pushdown(int x,int l,int r)
{
	// cout<<l<<"~"<<r<<":"<<col[x]<<','<<ck[x]<<','<<cb[x]<<'\n';
	if(col[x]!=-1)
	{
		ck[x<<1]=ck[x<<1|1]=0;
		cb[x<<1]=cb[x<<1|1]=0;
		mx[x<<1]=mx[x<<1|1]=col[x];
		mn[x<<1]=mn[x<<1|1]=col[x];
		col[x<<1]=col[x<<1|1]=col[x],col[x]=-1;
	}
	if(ck[x]||cb[x])
	{
		ck[x<<1]+=ck[x],ck[x<<1|1]+=ck[x];
		cb[x<<1]+=cb[x],cb[x<<1|1]+=cb[x];
		int mid=(l+r)/2;
		mx[x<<1]+=ck[x]*mid+cb[x];
		mx[x<<1|1]+=ck[x]*r+cb[x];
		mn[x<<1]+=ck[x]*l+cb[x];
		mn[x<<1|1]+=ck[x]*(mid+1)+cb[x];
		ck[x]=cb[x]=0;
	}
}
void add(int nl,int nr,int l,int r,int k,int b,int x)
{
	if(l<=nl&&nr<=r)
	{
		ck[x]+=k;
		cb[x]+=b;
		mx[x]+=k*nr+b;
		mn[x]+=k*nl+b;
		return;
	}
	int mid=(nl+nr)/2;
	pushdown(x,l,r);
	if(l<=mid)add(nl,mid,l,r,k,b,x<<1);
	if(r>mid)add(mid+1,nr,l,r,k,b,x<<1|1);
	pushup(x);
}
int query(int l,int r,int p,int x)
{
	if(l==r)
	{
		return mx[x];
	}
	int mid=(l+r)/2;
	pushdown(x,l,r);
	if(p<=mid)return query(l,mid,p,x<<1);
	else return query(mid+1,r,p,x<<1|1);
}
void upd(int x,int p){mx[x]=mn[x]=p,col[x]=p,ck[x]=cb[x]=0;}
void modify(int nl,int nr,int l,int r,int p,int x)
{
	if(mx[x]<=p)return;
	if(nl==nr)
	{
		// cout<<nl<<"~"<<nr<<'\n';
		upd(x,p);
		return;
	}
	int mid=(nl+nr)/2;
	pushdown(x,nl,nr);
	if(l<=nl&&nr<=r)
	{
		if(mn[x]>p)
		{
			// cout<<nl<<"~"<<nr<<'\n';
			upd(x,p);
		}
		else
		{
			modify(nl,mid,l,r,p,x<<1);
			modify(mid+1,nr,l,r,p,x<<1|1);
		}
		pushup(x);
		return;
	}
	if(l<=mid)modify(nl,mid,l,r,p,x<<1);
	if(r>mid)modify(mid+1,nr,l,r,p,x<<1|1);
	pushup(x);
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(col,-1,sizeof(col));
	int n=qr,y=qr;
	for(int i=1;i<=n;i++)s[i]=nc()=='?';
	int pos=0;
	for(int i=n;i>=1;i--)
	{
		if(s[i])
		{
			// cout<<"+=x-"<<pos<<'\n';
			add(0,n,pos,n,1,-pos,1);
		}
		else pos++;
		// cout<<"pos="<<pos<<'\n';
		// cout<<"min with "<<query(0,n,pos,1)+y<<'\n';
		modify(0,n,pos,n,query(0,n,pos,1)+y,1);
	}
	cout<<query(0,n,pos,1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 35536kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 3ms
memory: 35308kb

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 8ms
memory: 36844kb

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 35636kb

input:

10 0
++?+??++??

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 5ms
memory: 35696kb

input:

12 100
+?+++??+??++

output:

19

result:

ok single line: '19'

Test #6:

score: 0
Accepted
time: 10ms
memory: 35528kb

input:

1 1
?

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 7ms
memory: 36084kb

input:

9 7
++++++++?

output:

7

result:

ok single line: '7'

Test #8:

score: 0
Accepted
time: 15ms
memory: 36716kb

input:

9 8
++++++++?

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 3ms
memory: 36128kb

input:

10 15
++++++++??

output:

15

result:

ok single line: '15'

Test #10:

score: 0
Accepted
time: 5ms
memory: 35620kb

input:

5 3
+?+?+

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 3ms
memory: 36732kb

input:

10 5
+?+?+??+??

output:

10

result:

ok single line: '10'

Test #12:

score: 0
Accepted
time: 16ms
memory: 36192kb

input:

10 7
+?+?+??+??

output:

12

result:

ok single line: '12'

Test #13:

score: 0
Accepted
time: 2ms
memory: 36560kb

input:

15 4
+?+?+??+??+??+?

output:

14

result:

ok single line: '14'

Test #14:

score: 0
Accepted
time: 4ms
memory: 35064kb

input:

15 6
+?+?+??+??+??+?

output:

18

result:

ok single line: '18'

Test #15:

score: -100
Wrong Answer
time: 9ms
memory: 36808kb

input:

19 8
+?+?+??+??+??+?++??

output:

30

result:

wrong answer 1st lines differ - expected: '28', found: '30'