QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#770065 | #9543. Good Partitions | LIYIBO123 | WA | 109ms | 23700kb | C++14 | 1.6kb | 2024-11-21 20:29:46 | 2024-11-21 20:29:46 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
inline int read(){
register int x=0,f=0;
register char c=getchar();
while(c>'9'||c<'0')f|=(c=='-'),c=getchar();
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^'0');
c=getchar();
}return f?(-x):x;
}
int T,a[200001],n,q,ans,c[200001],cha[200001];
vector<int>ys[200001];
inline void add(int x,int y){for(;x<=n;x+=(x&(-x)))c[x]+=y;}
inline int ask(int x){int fh=0;for(;x;x-=(x&(-x)))fh+=c[x];return fh;}
inline void check(){
ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=(n/i);j++)if(ask(j*i)-ask((j-1)*i+1))cha[i]++;
ans+=(cha[i]==0);
}
}
inline void ad(int x){
add(x,1);
for(auto v:ys[x]){
if(ask(x)-ask(x-v+1))cha[v]++;
if(cha[v]==1)ans--;
}
}
inline void de(int x){
add(x,-1);
for(auto v:ys[x]){
if(ask(x)-ask(x-v+1)==0)cha[v]--;
if(cha[v]==0)ans++;
}
}
int main(){
//freopen("11.in","r",stdin);
//freopen("11.out","w",stdout);
for(ll i=1;i<=200000;i++){
ys[i].push_back(i);
for(ll j=i;i*j<=200000;j++)ys[j*i].push_back(i);
}
T=read();
while(T--){
n=read(),q=read();
for(int i=1;i<=n;i++)c[i]=cha[i]=0;
for(int i=1;i<=n;i++){
a[i]=read();
if(a[i]<a[i-1])add(i,1);
}check();
printf("%d\n",ans);
for(int i=1;i<=q;i++){
int p=read(),v=read();
if(p!=1){
if(a[p]>=a[p-1]&&v<a[p-1])ad(p);
else if(a[p]<a[p-1]&&v>=a[p-1])de(p);
}
if(p!=n){
if(a[p]<=a[p+1]&&v>a[p+1])ad(p+1);
else if(a[p]>a[p+1]&&v<=a[p+1])de(p+1);
}
a[p]=v;printf("%d\n",ans);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 35ms
memory: 22264kb
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: 35ms
memory: 22084kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 109ms
memory: 23700kb
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:
89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 89990 89992 ...
result:
wrong answer 1st lines differ - expected: '160', found: '89990'