QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682019#9409. SensorskikcerAC ✓789ms284288kbC++175.4kb2024-10-27 13:32:242024-10-27 13:32:25

Judging History

This is the latest submission verdict.

  • [2024-10-27 13:32:25]
  • Judged
  • Verdict: AC
  • Time: 789ms
  • Memory: 284288kb
  • [2024-10-27 13:32:24]
  • Submitted

answer

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <bitset>
#include <map>
#include <fstream>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <unordered_set>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
void solve();
void init();
int main()
{
    init();
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

void init()
{
#ifdef ONLINE_JUDGE
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    cout.tie(nullptr);
#endif
}
#define int long long
template <typename T>
class SegTreeLazyRangeAdd
{
public:
    vector<T> tree;
    vector<T> *arr;
    vector<T> ini;
    vector<vector<int>> sets;
    vector<pair<int, int>> lr;
    ll ans;
    int n, root, n4, end;

    void maintain(int cl, int cr, int p)
    {
    }

    T range_sum(int l, int r, int cl, int cr, int p)
    {
        if (l <= cl && cr <= r)
            return tree[p];
        int m = cl + (cr - cl) / 2;
        T sum = 0;
        maintain(cl, cr, p);
        if (l <= m)
            sum += range_sum(l, r, cl, m, p * 2);
        if (r > m)
            sum += range_sum(l, r, m + 1, cr, p * 2 + 1);
        return sum;
    }
    void check(int p, int pl, int pr, vector<int> &sum)
    {
        // cerr<<'!'<<p<<' '<<pl<<' '<<pr<<' '<<tree[p]<<endl;
        if (tree[p] > 1)
            return;
        else if (tree[p] == 1)
        {
            for (auto id : sets[p])
            {
                sum[id] -= (ini[p] - tree[p]);
                if (sum[id] == 1)
                {
                    ans += id * id;
                }
            }
        }
        else
        {
            for (auto id : sets[p])
            {
                sum[id] -= 1;
                if (sum[id] == 0)
                {
                    ans -= id * id;
                }
                if (sum[id] == 1)
                {
                    ans += id * id;
                }
            }
        }
        // cerr<<'*'<<ans<<endl;
    }
    void add(int l, int r, T val, int x, int p, vector<int> &sum)
    {
        if (l == x && r == x)
        {
            tree[p]--;
            check(p, l, r, sum);
            return;
        }
        // maintain(cl, cr, p);
        int m = l + r >> 1;
        if (x <= m)
            add(l, m, val, x, p * 2, sum);
        else
            add(m + 1, r, val, x, p * 2 + 1, sum);
        tree[p] = tree[p * 2] + tree[p * 2 + 1];
        check(p, l, r, sum);
    }
    void setans(ll s)
    {
        ans = s;
    }
    void build(int s, int t, int p)
    {
        lr[p] = {s, t};
        if (s == t)
        {
            ini[p] = tree[p] = (*arr)[s];
            return;
        }
        int m = s + (t - s) / 2;
        build(s, m, p * 2);
        build(m + 1, t, p * 2 + 1);
        ini[p] = tree[p] = tree[p * 2] + tree[p * 2 + 1];
    }

public:
    explicit SegTreeLazyRangeAdd<T>(vector<T> v)
    {
        n = v.size();
        n4 = n * 4;
        ans = 0;
        tree = vector<T>(n4, 0);
        lr = vector<pair<int, int>>(n4);
        ini = tree;
        // lazy = vector<T>(n4, 0);
        sets = vector<vector<int>>(n4);
        arr = &v;
        end = n - 1;
        root = 1;
        build(0, end, 1);
        arr = nullptr;
    }
    void init(int p, int pl, int pr, int l, int r, int id)
    {
        if (pl >= l && pr <= r)
        {
            sets[p].push_back(id);
            return;
        }
        int mid = pl + (pr - pl) / 2;
        // cerr<<p<<' '<<pl<<' '<<pr<<' '<<l<<' '<<r<<endl;
        if (l <= mid)
            init(p * 2, pl, mid, l, r, id);
        if (r > mid)
            init(p * 2 + 1, mid + 1, pr, l, r, id);
    }

    void show()
    {
        cout << "S:";
        for (int i = root; i < n4; i++)
            cout << i << ' ' << lr[i].first << ' ' << lr[i].second << endl;
    }
    void Add(int x, T val, vector<int> &sum) { add(0, end, val, x, root, sum); }
    void Init(int l, int r, int id) { init(root, 0, end, l, r, id); }
};
void solve()
{
    int n, m;
    cin >> n >> m;
    int t = max(n, m);
    vector<int> l(t + 1), r(t + 1);
    for (int i = 1; i <= m; i++)
        cin >> l[i] >> r[i];
    vector<int> a(t + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    vector<int> init(n + 1, 1);
    SegTreeLazyRangeAdd<int> sgt(init);
    // cout<<sgt.range_sum(2,4,0,n-1,1);
    vector<int> sum(t + 1, 0);
    // vector<vector<pair<int, int>>> nodes(m + 1);
    ll ans = 0;
    for (int i = 1; i <= m; i++)
    {
        sum[i] = r[i] - l[i] + 1;
        if (sum[i] == 1)
            ans += i * i;
    }
    sgt.setans(ans);
    // cerr<<1<<endl;
    for (int i = 1; i <= m; i++)
    {
        // cerr<<i<<' '<<l[i]<<' '<<r[i]<<':';
        // cerr<<nodes[i].size()<<endl;
        sgt.Init(l[i], r[i], i);
        // for(auto x:nodes[i])
        // 	cerr<<x.first<<' '<<x.second<<endl;
        // cerr<<endl;
    }
    cout << ans << ' ';
    for (int i = 1; i <= n; i++)
    {
        a[i] = (a[i] + ans) % n;
        // cerr<<'~'<<a[i]<<' '<<ans<<endl;
        sgt.Add(a[i], -1, sum);
        ans = sgt.ans;
        cout << ans << ' ';
    }
    // sgt.show();
    cout << '\n';
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

input:

3
5 4
2 4
2 3
3 3
0 2
3 2 4 2 0
2 1
1 1
1 0
2 1
0 1
0 0

output:

9 13 29 17 16 0 
1 1 0 
0 1 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 283ms
memory: 43528kb

input:

2227
2 9
0 1
1 1
0 1
0 0
0 1
0 1
0 0
1 1
0 1
1 1
3 1
0 2
1 2 2
8 2
0 2
3 5
7 4 0 3 2 6 4 1
6 2
1 3
0 1
0 0 5 1 4 2
1 6
0 0
0 0
0 0
0 0
0 0
0 0
0
5 1
1 4
0 1 2 3 3
5 3
0 3
4 4
2 2
0 4 0 0 0
5 10
0 2
3 3
1 3
1 4
1 3
0 4
2 4
0 0
0 1
4 4
3 1 3 4 1
8 4
0 5
0 1
6 7
3 4
1 3 3 5 2 3 5 3
2 7
1 1
0 0
0 0
1 1
...

output:

133 220 0 
0 0 1 0 
0 0 0 0 4 4 5 4 0 
0 4 4 4 4 5 0 
91 0 
0 0 0 0 1 0 
13 13 4 0 1 0 
168 249 105 135 136 0 
0 4 13 9 0 0 16 17 0 
79 127 0 
1 54 0 
0 0 25 25 25 61 40 57 21 14 0 
385 0 
0 0 9 71 9 53 69 0 
0 0 9 9 9 46 0 
35 39 203 0 
1 10 9 9 9 54 0 
5 5 5 0 0 
5 13 13 4 16 16 16 0 
4 4 5 5 5 4 ...

result:

ok 2227 lines

Test #3:

score: 0
Accepted
time: 789ms
memory: 227396kb

input:

1
500000 500000
369902 382967
262235 295509
296241 456925
21398 104992
37225 97384
380549 388723
338331 494405
150247 262207
70049 286642
214690 432702
268101 392964
99683 217894
89569 351594
126467 380939
152103 169827
171887 422097
166531 416410
44667 160325
210347 371355
47557 119914
74437 200422...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...9642788310 20801182804434259 0 '

Test #4:

score: 0
Accepted
time: 312ms
memory: 214292kb

input:

1
500000 500000
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 41666791666750000 0 '

Test #5:

score: 0
Accepted
time: 350ms
memory: 284288kb

input:

1
500000 500000
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 41666791666750000 0 '

Test #6:

score: 0
Accepted
time: 332ms
memory: 178228kb

input:

1
500000 250000
0 250000
1 250001
2 250002
3 250003
4 250004
5 250005
6 250006
7 250007
8 250008
9 250009
10 250010
11 250011
12 250012
13 250013
14 250014
15 250015
16 250016
17 250017
18 250018
19 250019
20 250020
21 250021
22 250022
23 250023
24 250024
25 250025
26 250026
27 250027
28 250028
29 2...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...18019441588 4838325779633316 0 '

Extra Test:

score: 0
Extra Test Passed