QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22328 | #2356. Partition of Queries | hy_zheng_zai_nei_juan# | WA | 13ms | 36748kb | C++20 | 3.3kb | 2022-03-09 15:30:51 | 2022-04-30 00:54:13 |
Judging History
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];
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: 4ms
memory: 36332kb
input:
6 5 ++??+?
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 2ms
memory: 36508kb
input:
6 8 ++??+?
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 2ms
memory: 35700kb
input:
5 1 +++++
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 3ms
memory: 36728kb
input:
10 0 ++?+??++??
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 3ms
memory: 36008kb
input:
12 100 +?+++??+??++
output:
19
result:
ok single line: '19'
Test #6:
score: 0
Accepted
time: 2ms
memory: 36648kb
input:
1 1 ?
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 5ms
memory: 35796kb
input:
9 7 ++++++++?
output:
7
result:
ok single line: '7'
Test #8:
score: 0
Accepted
time: 13ms
memory: 36748kb
input:
9 8 ++++++++?
output:
8
result:
ok single line: '8'
Test #9:
score: 0
Accepted
time: 4ms
memory: 36204kb
input:
10 15 ++++++++??
output:
15
result:
ok single line: '15'
Test #10:
score: 0
Accepted
time: 4ms
memory: 36684kb
input:
5 3 +?+?+
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 4ms
memory: 36488kb
input:
10 5 +?+?+??+??
output:
10
result:
ok single line: '10'
Test #12:
score: 0
Accepted
time: 5ms
memory: 36460kb
input:
10 7 +?+?+??+??
output:
12
result:
ok single line: '12'
Test #13:
score: -100
Wrong Answer
time: 4ms
memory: 35108kb
input:
15 4 +?+?+??+??+??+?
output:
16
result:
wrong answer 1st lines differ - expected: '14', found: '16'