QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734721 | #9543. Good Partitions | XiaoretaW | RE | 3ms | 7616kb | C++20 | 2.7kb | 2024-11-11 14:35:38 | 2024-11-11 14:35:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define fi first
#define se second
#define ll long long
#define pb push_back
#define pii pair<ll, int>
#define all(a) a.begin(), a.end()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define per(i,b,a) for(int i = b-;1 i >= a; --i)
const int N = 200010;
int tr[4*N];
void update(int p){
tr[p] = gcd(tr[p*2], tr[p*2+1]);
}
void build(int p, int l, int r){
if(l == r){
tr[p] = 0;
return;
}
int mid = (l + r) >> 1;
build(p*2, l, mid);
build(p*2+1, mid+1, r);
update(p);
}
void change(int p, int l, int r, int pos, int val){
if(l == r){
assert(l == pos);
tr[p] = val;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid) change(p*2, l, mid, pos, val);
else change(p*2+1, mid+1, r, pos, val);
update(p);
}
int query(){
return tr[1];
}
int prime[N];
bool m[N];
int pn[N];
int minp[N];
int pcnt=0;
void sift(){
pn[1]=1;
for(int i=2;i<N;i++){
if(!m[i]){
pn[i]=2;
prime[pcnt++]=i;
minp[i]=i;
}
for(int j=0;prime[j]<=(N-1)/i;j++){
m[i*prime[j]]=1;
minp[i*prime[j]]=prime[j];
if(i%prime[j]){
pn[i*prime[j]]=pn[i]*2;
}
else{
int cnt=2;
int ti=i;
while(ti%minp[i]==0){
ti/=minp[i];
cnt++;
}
pn[i*prime[j]]=pn[ti]*cnt;
break;
}
}
}
}
void solve(){
int n, q; cin >> n >> q;
build(1, 1, n);
vi a(n+1); rep(i,1,n+1) cin >> a[i];
vi g(n+1);
rep(i,1,n) if(a[i] > a[i+1]){
g[i] = i;
change(1, 1, n, i, i);
}
vi ans; ans.reserve(q+1);
ans.pb(pn[query()]);
while(q--){
int p, v; cin >> p >> v;
a[p] = v;
if(g[p]){
if(p+1 <= n and a[p] <= a[p+1]){
g[p] = 0;
change(1, 1, n, p, 0);
}
}else{
if(p+1 <= n and a[p] > a[p+1]){
g[p] = p;
change(1, 1, n, p, p);
}
}
if(p-1 >= 0){
if(a[p-1] > a[p]){
g[p-1] = p-1;
change(1, 1, n, p-1, p-1);
}else{
g[p-1] = 0;
change(1, 1, n, p-1, 0);
}
}
// debug(g, query());
ans.pb(pn[query()]);
}
for(int a: ans) cout << a << '\n';
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
sift();
int T; cin >> T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 7616kb
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
Runtime Error
input:
1 1 1 2000000000 1 1999999999