QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730693 | #9543. Good Partitions | gates_orz | WA | 276ms | 13400kb | C++20 | 4.0kb | 2024-11-09 21:05:24 | 2024-11-09 21:05:25 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
//#define int LL
#define inl inline
const int N = 3e5 + 10;
const int M = N * 2;
//const int mod=998244353;
const int mod = 1000000007;
const double eps = 1e-8;
//const int mod=1e9+7;
typedef pair<int, int> PII;
//const int INF=0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int n, m;
void become_faster() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
#define lc u<<1
#define rc u<<1|1
struct Node {
int l,r;
int g;
};
Node tr[N*4];
int sa[N];
void push_up(int u) {
tr[u].g=__gcd(tr[lc].g,tr[rc].g);
}
void build(int u,int l,int r) {
tr[u]={l,r};
if(l==r)return;
int mid=(l+r)/2;
build(lc,l,mid),build(rc,mid+1,r);
}
void modify(int u,int k,int x) {
if(tr[u].l==tr[u].r) {
tr[u].g=x;
return;
}
else {
int mid=(tr[u].l+tr[u].r)/2;
if(k<=mid)modify(lc,k,x);
else modify(rc,k,x);
push_up(u);
}
}
int query(int u,int l,int r) {
if(tr[u].l>=l&&tr[u].r<=r) {
return tr[u].g;
}
else {
int mid=(tr[u].l+tr[u].r)/2;
int res=0;
if(l<=mid)res=__gcd(res,query(lc,l,r));
if(r>mid)res=__gcd(res,query(rc,l,r));
return res;
}
}
int find_first_num(int u,int l,int r) {
if(tr[u].l>r||tr[u].r<l)return -1;
if(tr[u].l>=l&&tr[u].r<=r&&!tr[u].g)return -1;
if(tr[u].l==tr[u].r)return tr[u].l;
int res=-1;
res=find_first_num(lc,l,r);
if(res==-1)res=find_first_num(rc,l,r);
return res;
}
int find_last_num(int u,int l,int r) {
if(tr[u].l>r||tr[u].r<l)return -1;
if(tr[u].l>=l&&tr[u].r<=r&&!tr[u].g)return -1;
if(tr[u].l==tr[u].r)return tr[u].l;
int res=-1;
res=find_last_num(rc,l,r);
if(res==-1)res=find_last_num(lc,l,r);
return res;
}
int f[N];
void init() {
for(int i=1;i<=200000;i++) {
for(int j=1;j*j<=i;j++) {
if(i%j==0) {
f[i]++;
if(i%(i/j)==0&&j!=i/j)f[i]++;
}
}
}
}
void solve() {
cin>>n>>m;
f[0]=n;
for(int i=1;i<=n;i++) {
cin>>sa[i];
}
build(1,1,n);
int last=1;
for(int i=1;i<=n;i++) {
if(sa[i]<sa[i-1]) {
modify(1,i,i-last);
last=i;
}
}
auto debug=[&]() {
cerr << "debug: " << "\n";
for (int i = 1; i <= n; i++) {
cerr << query(1, i, i) << " ";
}
cerr << "\n";
};
//debug();
int res=query(1,1,n);
//if(res==0)res=n;
//cout<<"f: "<<f[res]<<"\n";
//cout<<"res="<<res<<"\n";
cout<<f[res]<<"\n";
while(m--) {
int p,x;
cin>>p>>x;
sa[p]=x;
if(sa[p]>=sa[p-1]) {
if(p+1<=n&&sa[p+1]>=sa[p])modify(1,p+1,0);
modify(1,p,0);
if(p+1<=n&&sa[p+1]<sa[p])modify(1,p+1,1);
int p1=find_last_num(1,1,p);
if(p1==-1)p1=1;
if(p+1<=n) {
int p2=find_first_num(1,p+1,n);
if(p2!=-1)modify(1,p2,p2-p1);
}
}
else {
if(p+1<=n&&sa[p+1]>=sa[p])modify(1,p+1,0);
if(p-1>=1) {
int p1 = find_last_num(1, 1, p - 1);
if (p1 == -1)p1 = 1;
modify(1, p, p - p1);
}
if(p+1<=n) {
int p2=find_first_num(1,p+1,n);
if(p2!=-1) {
modify(1,p2,p2-p);
}
}
}
//debug();
res=query(1,1,n);
//if(res==0)res=n;
//cout<<"f: "<<f[res]<<"\n";
//cout<<"res="<<res<<"\n";
cout<<f[res]<<"\n";
}
}
/*
1
5 2
4 3 2 6 1
2 5
3 5
1
5 2
4 5 2 6 1
2 5
3 5
1
5 2
4 5 5 6 1
2 5
3 5
*/
signed main() {
become_faster();
int T = 1;
//T=read();
init();
cin>>T;
//for(int i=1;i<=100;i++)solve(i);
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 115ms
memory: 4456kb
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: 116ms
memory: 4388kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 238ms
memory: 13400kb
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: 276ms
memory: 13176kb
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: 231ms
memory: 12788kb
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: 105ms
memory: 6428kb
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: 113ms
memory: 6492kb
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 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 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'