QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620280 | #9246. Dominating Point | ucup-team5071# | WA | 8ms | 141240kb | C++20 | 4.1kb | 2024-10-07 17:19:55 | 2024-10-07 17:19:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
typedef long long ll;
const ll p1=100,p2=131;
const ll mod1=1e9+7,mod2=1e9+9;
typedef pair<ll,ll> hs;
const hs p =make_pair(p1,p2);
void add(ll &x,ll y,ll mod){
if((x+=y)>=mod)x-=mod;
}
void del(ll &x,ll y,ll mod){
if((x-=y)<0)x+=mod;
}
hs &operator+=(hs &a,hs b){
add(a.first,b.first,mod1);
add(a.second,b.second,mod2);
if(a.first<0)a.first+=mod1;
if(a.second<0)a.second+=mod2;
return a;
}
hs operator+(hs a,hs b){return a+=b;}
hs &operator-=(hs &a,hs b){
del(a.first,b.first,mod1);
del(a.second,b.second,mod2);
if(a.first>=mod1)a.first-=mod1;
if(a.second>=mod2)a.second-=mod2;
return a;
}
hs operator-(hs a,hs b){return a-=b;}
hs &operator*=(hs &a,hs b){
a.first=a.first*b.first%mod1;
a.second=a.second*b.second%mod2;
return a;
}
hs operator*(hs a,hs b){return a*=b;}
hs operator*(hs a,ll b){
a.first=a.first*b%mod1;
a.second=a.second*b%mod2;
return a;
}
hs Pow[maxn],Sum[maxn];
const ll inf =1e9;
struct Hash{
ll len;
hs h;
Hash(ll x=0){
len=1;h={x,x};
}
};
Hash Zero()
{
Hash a;
a.len=0;
a.h={0,0};
return a;
}
Hash operator+(Hash h1,Hash h2){
h1.len+=h2.len;
h1.h=h1.h*Pow[h2.len]+h2.h;
return h1;
}
struct Node{
int l,r;
Hash res;
ll tag;
};
struct SegmentTree{
Node a[maxn*4];
void tag_init(int i){
a[i].tag=0;
}
void tag_union(int fa,int i){
a[i].tag+=a[fa].tag;
}
void tag_cal(int i){
if(a[i].tag>0)a[i].res.h+=Sum[a[i].res.len]*a[i].tag;
if(a[i].tag<0)a[i].res.h-=Sum[a[i].res.len]*(-a[i].tag);
}
void pushdown(int i){
tag_cal(i);
if(a[i].l!=a[i].r){
tag_union(i,i*2);
tag_union(i,i*2+1);
}
tag_init(i);
}
void pushup(int i){
if(a[i].l==a[i].r)return;
pushdown(i*2);
pushdown(i*2+1);
a[i].res=a[i*2].res+a[i*2+1].res;
}
void build(int i,int l,int r){
a[i].l=l,a[i].r=r;tag_init(i);
if(l>=r)return;
int mid=(l+r)/2;
build(i*2,l,mid);
build(i*2+1,mid+1,r);
}
void update(int i,int l,int r,ll w){
pushdown(i);
if(a[i].r<l||a[i].l>r||l>r)return;
if(a[i].l>=l&&a[i].r<=r){
a[i].tag=w;
return;
}
update(i*2,l,r,w);
update(i*2+1,l,r,w);
pushup(i);
}
Hash query(int i,int l,int r){
pushdown(i);
if(a[i].r<l||a[i].l>r||l>r)return Zero();
if(a[i].l>=l&&a[i].r<=r){
return a[i].res;
}
return query(i*2,l,r)+query(i*2+1,l,r);
}
}tri1,tri2;
int main()
{
Pow[0]={1,1};
Sum[0]={1,1};
for(int i=1;i<maxn;i++){
Pow[i]=Pow[i-1]*p;
Sum[i]=Pow[i]+Sum[i-1];
}
ios::sync_with_stdio(false);
cin.tie(0);
int n,q;
ll k,b;
cin>>n>>q>>k>>b;
tri1.build(1,1,n);
tri2.build(1,1,n);
for(ll i=1;i<=n;i++){
int x;cin>>x;
tri1.update(1,i,i,x);
tri2.update(1,n-i+1,n-i+1,x-(n-i+1)*k);
}
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
Hash h= tri1.query(1,i,j);
cout<<"i="<<i<<" j="<<j<<" "<<h.h.first<<" "<<h.len<<endl;
}
}
while(q--){
int op;cin>>op;
if(op==1){
int l,r;cin>>l>>r;
ll w;cin>>w;
tri1.update(1,l,r,w);
tri2.update(1,n-r+1,n-l+1,w);
}
else{
int x;cin>>x;
int l1=x,l2=n-x+1;
if(!(l1<=n&&l2>0)){cout<<0<<"\n";continue;}
int l=1,r=min(n-l1+1,n-l2+1),res=0;
while(l<=r){
int mid=(l+r)/2;
if(tri1.query(1,l1+1,l1+mid).h==(tri2.query(1,l2+1,l2+mid).h+Sum[mid-1]*(k*l2))){
res=mid;l=mid+1;
}
else r=mid-1;
}
cout<<res<<"\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 141240kb
input:
6 011010 000101 010111 100001 010100 100010
output:
i=1 j=1 10100101 1 i=1 j=2 11030193 2 i=1 j=3 113120303 3 i=1 j=4 322131233 4 i=1 j=5 223224086 5 i=1 j=6 332509456 6 i=2 j=2 1020100 1 i=2 j=3 112111010 2 i=2 j=4 221201933 3 i=2 j=5 130294156 4 i=2 j=6 39516519 5 i=3 j=3 10101010 1 i=3 j=4 20202003 2 i=3 j=5 30301296 3 i=3 j=6 40230589 4 i=4 j=4 1...
result:
wrong output format Expected integer, but "i=1" found