QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771155 | #9543. Good Partitions | yld | WA | 436ms | 145172kb | C++20 | 4.0kb | 2024-11-22 10:14:12 | 2024-11-22 10:14:14 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
const int MAXN=1e6+5;
int fac[MAXN];
struct SegmentTree{
int l,r,gcd;
}tr[MAXN<<4];
void update(int rt)
{
tr[rt].gcd=__gcd(tr[ls].gcd,tr[rs].gcd);
}
void build(int l,int r,int rt)
{
tr[rt].l=l,tr[rt].r=r;
tr[rt].gcd=0;
if(l==r) return;
int mid=l+r>>1;
build(l,mid,ls);
build(mid+1,r,rs);
update(rt);
}
void modify(int pos,int rt,int c)
{
if(tr[rt].l==tr[rt].r)
{
tr[rt].gcd=c;
return;
}
int mid=tr[rt].l+tr[rt].r>>1;
if(pos<=mid) modify(pos,ls,c);
else modify(pos,rs,c);
update(rt);
}
vector<int> len(MAXN<<3);
void solve()
{
fill(len.begin(),len.end(),0);
int n,q;
cin>>n>>q;
vector<int> pos[n+1];
vector<int> a(n+2);
multiset<pair<int,int>> st;
int cnt=0,tmp=0;
for(int i=1;i<=n;i++)
{
tmp++;
cin>>a[i];
if(a[i]<a[i-1])
{
len[++cnt]=tmp-1;
pos[tmp-1].push_back(cnt);
st.insert({i-tmp+1,i-1});
tmp=1;
}
}
a[0]=1e18;
len[++cnt]=tmp;
pos[tmp].push_back(cnt);
st.insert({n-tmp+1,n});
// for(auto [x,y]:st) cerr<<x<<' '<<y<<endl;
// for(int i=1;i<=cnt;i++) cerr<<len[i]<<' ';
// cerr<<endl;
// for(int i=1;i<=n;i++)
// {
// for(auto x:pos[i]) cerr<<x<<' ';
// cerr<<endl;
// }
const int maxn=1000000;
build(1,maxn,1);
for(int i=1;i<=cnt;i++) modify(i,1,len[i]);
auto del=[&](int l,int r)
{
if(l>r) return;
modify(pos[r-l+1].back(),1,0);
// cerr<<"============\n";
len[pos[r-l+1].back()]=0;
pos[r-l+1].pop_back();
st.erase({l,r});
};
auto add=[&](int l,int r)
{
if(l>r) return;
len[++cnt]=r-l+1;
modify(cnt,1,len[cnt]);
pos[len[cnt]].push_back(cnt);
st.insert({l,r});
};
auto query=[&]
{
auto [L,R]=*st.rbegin();
modify(pos[R-L+1].back(),1,0);
int ans1=tr[1].gcd;
modify(pos[R-L+1].back(),1,R-L+1);
if(ans1==0) return n;
else return fac[ans1];
};
cout<<query()<<endl;
while(q--)
{
int p,x;
cin>>p>>x;
auto [l,r]=*prev(st.upper_bound({p,1e18}));
auto [L,R]=*prev(st.upper_bound({p-1,1e18}));
del(l,r);
a[p]=x;
// cerr<<"===========\n";
// cerr<<l<<' '<<r<<endl;
// cerr<<L<<' '<<R<<endl;
if(a[p]>=a[p-1])
{
// cout<<l<<' '<<r<<endl;
// cout<<L<<' '<<R<<endl;
if(l==L && r==R) add(l,r);
else
{
del(L,R);
add(L,r);
}
}
else
{
if(l==L && r==R) {add(L,p-1);add(p,r);}
else add(l,r);
}
// for(int i=1;i<=cnt;i++) cerr<<len[i]<<' ';
// cerr<<endl;
auto [ll,rr]=*prev(st.upper_bound({p,1e18}));
auto [LL,RR]=*prev(st.upper_bound({p+1,1e18}));
// cerr<<ll<<' '<<rr<<endl;
// cerr<<LL<<' '<<RR<<endl;
del(ll,rr);
if(a[p]<=a[p+1])
{
// cerr<<ll<<' '<<rr<<endl;
// cerr<<LL<<' '<<RR<<endl;
if(ll==LL && rr==RR) add(ll,rr);
else
{
del(LL,RR);
add(ll,RR);
}
}
else
{
if(ll==LL && rr==RR) {add(p+1,R);add(ll,p);}
else add(ll,rr);
}
cout<<query()<<endl;
// for(int i=1;i<=cnt;i++) cerr<<len[i]<<' ';
// cerr<<endl;
}
}
signed main()
{
for(int i=1;i<MAXN;i++)
for(int j=i;j<MAXN;j+=i) fac[j]++;
cin.tie(0)->sync_with_stdio(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 39ms
memory: 124932kb
input:
1 5 2 4 3 2 6 1 2 5 3 5
output:
1 2 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 42ms
memory: 124768kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 312ms
memory: 130800kb
input:
1 200000 200000 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160...
result:
ok 200001 lines
Test #4:
score: 0
Accepted
time: 436ms
memory: 145172kb
input:
1 200000 200000 200001 200000 199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199970 199969 199968 199967 199966 199965 199964 199963 199962 1999...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 200001 lines
Test #5:
score: 0
Accepted
time: 263ms
memory: 131116kb
input:
1 200000 200000 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 200001 lines
Test #6:
score: 0
Accepted
time: 44ms
memory: 124772kb
input:
2 2 2 17017 63462 2 94054 2 13504 8 8 14380 5840 34752 73602 60279 26105 44308 78318 7 8597 2 70671 6 56663 5 90093 5 96853 3 10700 1 76875 6 27325
output:
2 2 1 1 1 1 1 1 1 1 1 1
result:
ok 12 lines
Test #7:
score: -100
Wrong Answer
time: 144ms
memory: 124852kb
input:
10 9 15 850456 510799 912572 938543 215712 758501 850577 149454 330027 7 740992 7 73826 1 993823 7 143019 8 152824 2 109975 5 151989 7 851016 3 157534 8 491512 6 987473 7 272348 3 842756 4 278214 5 707564 10 17 494099 922564 124251 422938 100551 915266 18436 74858 885629 897256 8 798574 7 49544 7 83...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 2 2 2 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
wrong answer 20th lines differ - expected: '1', found: '2'