QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756807 | #9543. Good Partitions | Stelor | WA | 293ms | 13528kb | C++17 | 3.7kb | 2024-11-16 22:01:28 | 2024-11-16 22:01:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class Info>
struct SGT {
#define l(p) (p << 1)
#define r(p) (p << 1 | 1)
int n;
std::vector<Info> info;
SGT() {}
SGT(int _n, Info _v = Info()) {
init(_n, _v);
}
template<class T>
SGT(std::vector<T> _init) {
init(_init);
}
void init(int _n, Info _v = Info()) {
init(std::vector(_n, _v));
}
template<class T>
void init(std::vector<T> _init) {
n = _init.size();
info.assign(4 << std::__lg(n), Info());
auto build = [&](auto self, int p, int l, int r) {
if (r - l == 1) {
info[p] = _init[l];
return;
}
int m = l + r >> 1;
self(self, l(p), l, m);
self(self, r(p), m, r);
pull(p);
};
build(build, 1, 0, n);
}
void pull(int p) { // 这个就是 y 总的 pushup
info[p] = info[l(p)] + info[r(p)];
}
void modify(int p, int l, int r, int x, const Info &v) {
if (r - l == 1) {
info[p] = v;
return;
}
int m = l + r >> 1;
if (x < m) {
modify(l(p), l, m, x, v);
} else {
modify(r(p), m, r, x, v);
}
pull(p);
}
void modify(int p, const Info &v) {
modify(1, 0, n, p, v);
}
Info query(int p, int l, int r, int x, int y) {
if (l >= y or r <= x) {
return Info();
}
if (l >= x and r <= y) {
return info[p];
}
int m = l + r >> 1;
return query(l(p), l, m, x, y) + query(r(p), m, r, x, y);
}
Info query(int l, int r) {
return query(1, 0, n, l, r);
}
#undef l
#undef r
};
struct Info {
// 注意: 模板下标是[0,n-1],在查询修改操作时记得对应,
//另外, query函数查询的是[l,r)
ll num;
Info(){
num=0;
}
Info(ll v){
num=v;
}
};
Info operator+(Info a, Info b) {
Info c;
c.num=gcd(a.num,b.num);
return c;
}
ll work(ll x){
ll ret=0;
for(int i=1;i<=x/i;++i){
if(x%i==0){
ret++;
if((x/i)!=i) ret++;
}
}
return ret;
}
void solve(){
int n,q;
cin >> n >> q;
vector<ll> p(n+10);
for(int i=1;i<=n;++i) cin >> p[i];
vector<Info> a(n+10);
for(int i=1;i<n;++i){
if(p[i]>p[i+1]){
a[i-1].num=i;
}else a[i-1].num=0;
}
SGT<Info> sgt(a);
if(n!=1){
cout<<work(sgt.query(0,n).num)<<'\n';
}
else cout<<"1\n";
while(q--){
ll idx,val;
cin >> idx >> val;
if(n==1){
cout<<"1\n";
continue;
}
if(idx==1){
if(val>p[idx+1]){
sgt.modify(idx-1,idx);
}else{
sgt.modify(idx-1,0);
}
}else if(idx==n){
if(p[idx-1]>val){
sgt.modify(idx-2,idx-1);
}else{
sgt.modify(idx-2,0);
}
}else{
if(val>p[idx+1]){
sgt.modify(idx-1,idx);
}else{
sgt.modify(idx-1,0);
}
if(p[idx-1]>val){
sgt.modify(idx-2,idx-1);
}else{
sgt.modify(idx-2,0);
}
}
p[idx]=val;
val=sgt.query(0,n).num;
cout<<work(val)<<'\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 0ms
memory: 3568kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 293ms
memory: 13528kb
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 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 ...
result:
wrong answer 2nd lines differ - expected: '200000', found: '0'