QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610752#2272. Formica Sokobanicaucup-team4153#WA 84ms21296kbC++202.4kb2024-10-04 17:16:542024-10-04 17:18:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 17:18:16]
  • 评测
  • 测评结果:WA
  • 用时:84ms
  • 内存:21296kb
  • [2024-10-04 17:16:54]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
const int N = 2e5 + 7;
typedef long long ll;

ll gcd(ll a, ll b) {
    if (!b)return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    if (a == 0 || b == 0)return 1;
    return a / gcd(a, b) * b;
}

struct info {
    ll v[3];
};

info operator+(const info &o1, const info &o2) {
    info ans;
    ans.v[0] = gcd(o1.v[0], o2.v[0]);
    ans.v[1] = lcm(gcd(o1.v[1], o2.v[0]), gcd(o1.v[0], o2.v[1]));
    ans.v[2] = lcm(gcd(o1.v[0], o2.v[2]), lcm(gcd(o1.v[2], o2.v[0]), gcd(o1.v[1], o2.v[1])));
    return ans;
}

struct node {
    int l, r;
    info v;

    void output() {
        for (int i = 0; i < 3; i++)cout << v.v[i] << " ";
        cout << "\n";
    }
} Tree[N << 2];

int n, m;
int a[N];

void build(int k, int l, int r) {
    Tree[k].l = l;
    Tree[k].r = r;
    if (l == r) {
        Tree[k].v.v[0] = a[l];
        Tree[k].v.v[1] = 1;
        Tree[k].v.v[2] = 0;
        return;
    }
    int mid = (l + r) >> 1;
    build(k << 1, l, mid);
    build(k << 1 | 1, mid + 1, r);
    Tree[k].v = Tree[k << 1].v + Tree[k << 1 | 1].v;
    if (l == 1 && r == 2){
        Tree[k].output();
        Tree[k<<1].output();
        Tree[k<<1|1].output();
    }
}

void update(int k, int pos, int v) {
    if (Tree[k].l == Tree[k].r) {
        Tree[k].v.v[0] = v;
        Tree[k].v.v[1] = Tree[k].v.v[2] = 1;
        return;
    }
    int mid = (Tree[k].l + Tree[k].r) >> 1;
    if (pos <= mid)update(k << 1, pos, v);
    else update(k << 1 | 1, pos, v);
    Tree[k].v = Tree[k << 1].v + Tree[k << 1 | 1].v;
}

info query(int k, int l, int r) {
    if (Tree[k].l >= l && Tree[k].r <= r)return Tree[k].v;
    int mid = (Tree[k].l + Tree[k].r) >> 1;
    if (r <= mid)return query(k << 1, l, r);
    if (l > mid)return query(k << 1 | 1, l, r);
    return query(k << 1, l, r) + query(k << 1 | 1, l, r);
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)cin >> a[i];
    build(1, 1, n);
//    return 0;
    while (m--) {
        char ch;
        cin >> ch;
        if (ch == 'Q') {
            int l, r, k;
            cin >> l >> r >> k;
            cout << query(1, l, r).v[k] << "\n";
        } else {
            int pos, v;
            cin >> pos >> v;
            update(1, pos, v);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 84ms
memory: 21296kb

input:

200000 67431
1 134415
1 3
1 4
11 1
13 1
19 1
1 25
31 1
1 33
41 1
46 1
48 1
1 52
1 55
60 1
63 1
1 77
78 1
85 1
1 86
1 87
90 1
92 1
95 1
1 96
1 98
1 103
1 115
1 123
1 126
1 128
1 130
137 1
140 1
141 1
1 142
153 1
162 1
165 1
167 1
1 169
1 170
177 1
1 187
1 189
1 190
1 193
1 197
202 1
1 216
1 220
1 222...

output:

1 1 134415 
1 1 0 
134415 1 0 

result:

wrong answer 1st lines differ - expected: '132569', found: '1 1 134415 '