QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#731659 | #9543. Good Partitions | forget-star# | WA | 3ms | 4684kb | C++14 | 1.1kb | 2024-11-10 10:18:58 | 2024-11-10 10:19:01 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
const int N=2e5+10;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int n,q,a[N],tr[N<<2],cnt[N];
void build(int k,int l,int r)
{
if(l==r)
{
if(l<n&&a[l]>a[l+1]) tr[k]=l;
else tr[k]=0;
return;
}
int mid=(l+r)>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
tr[k]=gcd(tr[k<<1],tr[k<<1|1]);
return;
}
void modify(int k,int l,int r,int x,int v)
{
if(l==r)
{
tr[k]=v;
return;
}
int mid=(l+r)>>1;
if(x<=mid) modify(k<<1,l,mid,x,v);
else modify(k<<1|1,mid+1,r,x,v);
tr[k]=gcd(tr[k<<1],tr[k<<1|1]);
return;
}
int main()
{
for(int i=1;i<=200000;i++)
for(int j=i;j<=200000;j+=i) cnt[j]++;
int T;scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
build(1,1,n);
printf("%d\n",cnt[tr[1]]);
while(q--)
{
int x,y;scanf("%d%d",&x,&y);a[x]=y;
if(x>1) modify(1,1,n,x-1,(a[x-1]>a[x])?x-1:0);
if(x<n) modify(1,1,n,x,(a[x]>a[x+1])?x:0);
printf("%d\n",cnt[tr[1]]);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4684kb
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: 3ms
memory: 4680kb
input:
1 1 1 2000000000 1 1999999999
output:
0 0
result:
wrong answer 1st lines differ - expected: '1', found: '0'