QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733532 | #9543. Good Partitions | SDNUyuqi | WA | 415ms | 32104kb | C++23 | 4.7kb | 2024-11-10 19:42:44 | 2024-11-10 19:42:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
const int N=1e6+100;
#define MAX 1e6
ll nu[N],len[N];
#define ls (n<<1)
#define rs (n<<1|1)
ll t[N<<2],lazy[N<<2];
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
void pushup(int n)
{
t[n]=gcd(t[ls],t[rs]);
}
void pushdown(int n)
{
if(lazy[n])
{
lazy[ls]=lazy[rs]=lazy[n];
t[ls]=t[rs]=lazy[n];
lazy[n]=0;
}
}
bool flag[N];
void create(int n,int l,int r)
{
if(l==r)
{
t[n]=len[l];
return ;
}
int mi=l+r>>1;
create(ls,l,mi);
create(rs,mi+1,r);
pushup(n);
}
void update(int n,int l,int r,int sl,int sr,int w)
{
if(l>sr||r<sl)
{
return ;
}
if(l>=sl&&r<=sr)
{
t[n]=w;
lazy[n]=w;
return ;
}
int mi=l+r>>1;
pushdown(n);
update(ls,l,mi,sl,sr,w);
update(rs,mi+1,r,sl,sr,w);
pushup(n);
}
ll answer(int n,int l,int r,int sl,int sr)
{
if(l>sr||r<sl)
{
return 0;
}
if(l>=sl&&r<=sr)
{
return t[n];
}
int mi=l+r>>1;
pushdown(n);
ll g=0;
g=gcd(g,answer(ls,l,mi,sl,sr));
g=gcd(g,answer(rs,mi+1,r,sl,sr));
return g;
}
set<pair<int,int>>s;
vector<ll>p;
ll an(ll n)
{
ll ans=1;
for(auto i:p)
{
if(i*i>n)
{
break;
}
int nu=0;
while(n%i==0)
{
nu++;
n/=i;
}
ans*=nu+1;
}
if(n!=1)
{
ans*=2;
}
return ans;
}
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
for(int i=2;i<=MAX;i++)
{
if(!flag[i])
{
p.push_back(i);
}
for(auto j:p)
{
if(i*j>=MAX)
{
break;
}
flag[i*j]=1;
if(i%j==0)
{
break;
}
}
}
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>nu[i];
}
for(int i=1;i<=n;i++)
{
int j=i;
while(j+1<=n&&nu[j+1]>=nu[j])
{
j++;
}
for(int k=i;k<=j;k++)
{
len[k]=j-i+1;
}
s.insert({i,j});
i=j;
}
create(1,1,n);
auto end=--s.upper_bound({n,MAX});
if(end->first==1)
{
cout<<n<<endl;
}
else
cout<<an(answer(1,1,n,1,end->first-1))<<endl;
for(int i=1;i<=m;i++)
{
int id,v;
cin>>id>>v;
nu[id]=v;
auto sign=--s.upper_bound({id,MAX});
int l=sign->first,r=sign->second;
s.erase(sign);
if(l!=id)
s.insert({l,id-1});
if(r!=id)
{
s.insert({id+1,r});
}
s.insert({id,id});
sign=--s.upper_bound({id,MAX});
l=sign->first,r=sign->second;
auto signl=sign;
auto signr=sign;
int ll,rr;
if(l==1)
{
ll=1;
}
else
{
signl--;
ll=signl->first;
}
if(r==n)
{
rr=n;
}
else
{
signr++;
rr=signr->second;
}
if(l!=ll&&nu[l]>=nu[l-1]&&r!=rr&&nu[r]<=nu[r+1])
{
s.erase(sign);
s.erase(signl);
s.erase(signr);
s.insert({ll,rr});
}
else if(l!=ll&&nu[l]>=nu[l-1])
{
s.erase(sign);
s.erase(signl);
s.insert({ll,r});
}
else if(r!=rr&&nu[r]<=nu[r+1])
{
s.erase(sign);
s.erase(signr);
s.insert({l,rr});
}
signl=--s.upper_bound({ll,MAX});
signr=s.upper_bound({rr,MAX});
for(auto i=signl;i!=signr;i++)
{
update(1,1,n,i->first,i->second,i->second-i->first+1);
}
end=--s.upper_bound({n,MAX});
if(end->first==1)
{
cout<<n<<endl;
continue;
}
cout<<an(answer(1,1,n,1,end->first-1))<<endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 12480kb
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: 3ms
memory: 10888kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 273ms
memory: 20428kb
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: 415ms
memory: 32104kb
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: 322ms
memory: 22920kb
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: 6ms
memory: 12192kb
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: 3ms
memory: 10944kb
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 2 1 1 2 1 2 1 2 2 2 2 2 2 1 1 1 1 1 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 18th lines differ - expected: '2', found: '1'