QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730502 | #9543. Good Partitions | 2366503423 | RE | 380ms | 26376kb | C++14 | 4.5kb | 2024-11-09 20:28:46 | 2024-11-09 20:28:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 23;
struct Node{
ll l, r;
ll v, d;
}tr[maxn * 4];
ll a[maxn], b[maxn];
ll yin[200005];
void pushup(Node &u, Node &l, Node &r)
{
u.v = l.v + r.v;
u.d = __gcd(l.d, r.d);
}
void pushup(ll u)
{
pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
//printf("%d[%d,%d]=%d\n",u,tr[u].l,tr[u].r,tr[u].d);
}
void build(ll u, ll l, ll r)
{
if(l == r) tr[u] = {l, r, b[l], b[l]};
else
{
tr[u] = {l, r};
ll mid = l + r >> 1;
build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
ll query(ll u, ll l, ll r)
{
if(tr[u].l >= l && tr[u].r <= r) return tr[u].d;
else
{
ll mid = tr[u].l + tr[u].r >> 1;
if(r <= mid) return query(u << 1, l, r);
else if(l > mid) return query(u << 1 | 1, l, r);
else return __gcd(query(u << 1, l, r), query(u << 1 | 1, l, r));
}
}
ll query2(ll u, ll l, ll r)
{
if(tr[u].l >= l && tr[u].r <= r) return tr[u].v;
else
{
ll mid = tr[u].l + tr[u].r >> 1;
if(r <= mid) return query2(u << 1, l, r);
else if(l > mid) return query2(u << 1 | 1, l, r);
else return query2(u << 1, l, r) + query2(u << 1 | 1, l, r);
}
}
void modify(ll u, ll p, ll v)
{
if(tr[u].l == tr[u].r && tr[u].l == p) tr[u].d += v, tr[u].v += v;
else
{
ll mid = tr[u].l + tr[u].r >> 1;
if(p <= mid) modify(u << 1, p, v);
else modify(u << 1 | 1, p, v);
pushup(u);
}
}
/*int main()
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]), b[i] = a[i] - a[i - 1];
build(1, 1, n);
char op[4];
ll op1 = 0, op2 = 0, op3 = 0;
while(m--)
{
scanf("%s%lld%lld", op, &op1, &op2);
if(*op == 'C')
{
scanf("%lld", &op3);
modify(1, op1, op3);
if(op2 + 1 <= n) modify(1, op2 + 1, -op3);
}
else
{
ll t = query2(1, 1, op1); //cout << t << endl;
printf("%lld\n", abs( __gcd(t, query(1, op1 + 1, op2))));
}
}
}*/
ll num(int n){ //\xb7\xb5\xbbص\xc4\xca\xc7\xd2\xf2\xd7\xd3\xd7\xdc\xca\xfd
ll count=2;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0){
if(i==sqrt(n) && n/i==i){ //\xc8\xe7\xb9\xfb\xc1\xbd\xd2\xf2\xd7\xd3\xcf\xe0ͬ\xa3\xac\xd4\xf2ֻ\xbc\xd31
count++;
}
else count+=2;
}
}
return count;
}
int main()
{
for(int j=1;j<=200005;j++)
{
ll sum=num(j);
yin[j]=sum;
}
yin[1]=1;
yin[0]=1;
int t;cin>>t;
while(t--)
{
int n,q;
cin>>n>>q;
vector <long long int> w(n+1,0);
for(int i=1;i<=n;i++) cin>>w[i];
long long int xian=0;
for(int i=1;i<n;i++)
{
if(w[i]>w[i+1]) a[i]=i;
else a[i]=0;
xian=__gcd(xian,a[i]);
}
a[n]=0;
if(xian!=0) cout<<yin[xian]<<'\n';
else cout<<n<<'\n';
for(int i=1;i<=n;i++) b[i] = a[i] - a[i - 1];
build(1,1,n);
if(q==1) {cout<<1<<'\n';return 0;}
while(q--)
{
long long int index,x;cin>>index>>x;
w[index]=x;
ll l,r,d;
if(index>1)
{
if(w[index-1]>w[index])
{
l=index-1;r=index-1;
d=index-1-a[index-1];a[index-1]=index-1;
modify(1, l, d);
if(r + 1 <= n) modify(1, r + 1, -d);
}
else
{
l=index-1;r=index-1;
d=0-a[index-1];a[index-1]=0;
modify(1, l, d);
if(r + 1 <= n) modify(1, r + 1, -d);
}
}
if(index<n)
{
if(w[index]>w[index+1])
{
l=index;r=index;
d=index-a[index];a[index]=index;
modify(1, l, d);
if(r + 1 <= n) modify(1, r + 1, -d);
}
else
{
l=index;r=index;
d=0-a[index];a[index]=0;
modify(1, l, d);
if(r + 1 <= n) modify(1, r + 1, -d);
}
}
ll t = query2(1, 1, 1); //cout << t << endl;
long long int zui=abs( __gcd(t, query(1, 1 + 1, n)));
if(zui>0) cout<<yin[zui]<<'\n';
else cout<<n<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 113ms
memory: 8736kb
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: 113ms
memory: 8940kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 358ms
memory: 26328kb
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: 348ms
memory: 26376kb
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: 380ms
memory: 26072kb
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: 113ms
memory: 10328kb
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
Runtime Error
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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