QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726356 | #9543. Good Partitions | 20225954 | WA | 2ms | 9768kb | C++20 | 4.0kb | 2024-11-08 23:16:32 | 2024-11-08 23:16:32 |
Judging History
answer
#include <bits/stdc++.h>
#define db(x) cerr<<#x<<(x)<<"\n"
#define db1(x) cerr<<#x<<(x)<<" "
#define ll long long
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int Mod = 1e9+7;
const int N = 2.1e5;
int n,m,q;
ll a[N],w[N],pos[N];
const ll inf = 3e10;
ll gd[N<<2];
bool ins[N];
void pushup(int o){
ll x1 =gd[o<<1],x2 =gd[o<<1|1];
//cout<<o<<" "<<x1<<" "<<x2<<" "<<__gcd(x1,x2)<<"\n";
gd[o] = __gcd(gd[o<<1],gd[o<<1|1]);
}
void build(int o,int l,int r){
if(l==r){
gd[o] =w[l];
pos[l] =o;
return ;
}
int mid = (l+r)>>1;
build (o<<1,l,mid);
build (o<<1|1,mid+1,r);
pushup(o);
}
void upd(int o,int l,int r,int pos,int v){
// if(pos==0)return;
if(l==pos){
gd[o] = v;
// cout<<"upd "<<"[pos,v] "<<pos<<" "<<v<<"\n";
return ;
}
int mid = (l+r)>>1;
if(pos<=mid)upd(o<<1,l,mid,pos,v);
else upd(o<<1|1,mid+1,r,pos,v);
pushup(o);
// cout<<"-----[l,r]"<<l<<" "<<r <<" gd: "<<gd[o]<<" \n";
}
ll que(int o,int l,int r,int s,int t){
//db(o);
if(s<=l&&r<=t){
// cout<<"[l,r]"<<l<<" r"<<r<<" "<<gd[o]<<"\n";
return gd[o];
}
int mid =(l+r)>>1;
ll gd1 =0,gd2 =0;
if(s<=mid)gd1 = que(o<<1,l,mid,s,t);
if(t>mid)gd2 = que(o<<1|1,mid+1,r,s,t);
int C = __gcd(gd1,gd2);
// cout<<"[l,r,x]"<<l<<" "<<r<<" "<<C<<"\n";
return C;
}
void solve()
{
set<int> s;
map<ll,int> mp;int tot =0;
s.insert(1);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=2;i<=n;i++){
if(a[i]<a[i-1]){
s.insert(i);
}
}
// db(s.size());
for(auto it = s.begin();it!=s.end();it++){
if(*it==1)continue;
ll x = *it;
int dif = x - *prev(it);
w[x] =dif;
// w[mp[x]] = dif;
}
// db(w[1]);
build(1,1,n);
ll nowgd = que(1,1,n,1,n);
auto ok=[&](ll x){
ll ans =0;
for(ll i=1;i*i<=x;i++){
if(x%i==0&&i*i!=x)ans+=2;
else ans++;
}
return ans;
};
cout<<ok(nowgd)<<"\n";
auto pr = [&](){
cout<<"nowtre:\n";
for(int i=1;i<=n;i++){
cout<<gd[pos[i]]<<" ";
}
cout<<"\n";
};
// pr();
for(int i=1;i<=q;i++){
int t,v;cin>>t>>v;
a[t] =v;
auto cal = [&](int p){
if(a[p]>=a[p-1]){
if(s.count(p)){
auto le = s.lower_bound(p);--le;
auto ri = s.upper_bound(p);
if(ri!=s.end()){
ll x2 = *ri-*le;
//db(x2-p);
upd(1,1,n,*ri,x2);
}
}
if(s.count(p))s.erase(p),upd(1,1,n,p,0);
// cout<<"mp[p]"<<mp[p]<<"\n";
// if(mp[p]!=0){
// //cout<<"mp[p]"<<mp[p]<<"\n";
// upd(1,1,n,mp[p],0);
// cout<<"upd "<<gd[1]<<"\n";
// mp[p] =0;
// }
}else if(a[p]<a[p-1]){
// if(!mp[p])mp[p] =++tot;
s.insert(p);
auto le = s.lower_bound(p);--le;
auto ri = s.upper_bound(p);
ll x1 = p-*le;
// db(i);db(p);db(*le);
upd(1,1,n,p,x1);
if(ri!=s.end()){
ll x2 = *ri;
// db(x2-p);
upd(1,1,n,x2,x2-p);
}
// s.insert()
}
};
cal(t);
if(t<n)cal(t+1);
// pr();
nowgd =que(1,1,n,1,n);
// cout<<"nowgd "<<nowgd <<"\n";
// nowgd =0;
// for(int i=1;i<=n;i++){
// nowgd = __gcd(nowgd,gd[pos[i]]);
// }
// cout<<"nowgd "<<nowgd <<"\n";
cout<<ok(nowgd)<<"\n";
}
}
int main()
{
//cout<<__gcd(0,4)<<"\n";
// cout<<ceil(1.2);
IOS;
int _ ;cin>>_;
while(_--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9768kb
input:
1 5 2 4 3 2 6 1 2 5 3 5
output:
1 2 3
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7660kb
input:
1 1 1 2000000000 1 1999999999
output:
0 0
result:
wrong answer 1st lines differ - expected: '1', found: '0'