Submission #1109275

# Submission time Handle Problem Language Result Execution time Memory
1109275 2024-11-06T10:08:18 Z Kerim Mosaic (IOI24_mosaic) C++17
100 / 100
892 ms 109640 KB
#include "bits/stdc++.h"
#define ll long long
#define pb push_back
#define pii pair<int, int>
using namespace std;

const int N = 4e5+5;
int cnt[N], arcalyk[4][N], tarhun[N][4];
ll pre[N], suf[N], cep[N], sag[N];

int wow(int a, int b){
    return (!(a|b)?1:0);
}

vector<ll> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R){
    int n = (int)X.size();
    for (int i = 0; i < n+n; i++)
        cnt[i] = 0;

    map<pii, int> mp;
    for(int i = 1; i <= n; ++i)
        mp[{1, i}] = X[i-1], mp[{i, 1}] = Y[i-1];
    for(int i = 2; i <= n; ++i)
        for(int j = 2; j <= 3; ++j)
            mp[{i, j}] = wow(mp[{i-1, j}], mp[{i, j-1}]);
    for(int i = 2; i <= 3; ++i)
        for(int j = 2; j <= n; ++j)
            mp[{i, j}] = wow(mp[{i-1, j}], mp[{i, j-1}]);

    int i = 3;
    for(int j = 3; j <= n; ++j)
        cnt[i-j+n] = mp[{i, j}];
    int j = 3;
    for(int i = 3; i <= n; ++i)
        cnt[i-j+n] = mp[{i, j}];

    for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= n; j++)
            arcalyk[i][j] = mp[{i,j}] + arcalyk[i][j-1];
    for (int j = 1; j <= 3; j++)
        for (int i = 1; i <= n; i++)
            tarhun[i][j] = mp[{i,j}] + tarhun[i-1][j];

    suf[n+n] = cep[n+n] = 0;
    sag[0] = pre[0] = cnt[0];
    for (int i = 1; i < n+n; i++){
        pre[i] = pre[i-1] + cnt[i];
        sag[i] = sag[i-1] + pre[i-1] + cnt[i];
    }
    for (int i = n+n-1; i >= 0; i--){
        suf[i] = suf[i+1] + cnt[i];
        cep[i] = cep[i+1] + suf[i+1] + cnt[i];
    }

    vector<ll> ans;
    for(int i = 0; i < (int)L.size(); ++i){
        int x = T[i]+1, y = L[i]+1, yy = R[i]+1, xx = B[i]+1;
        ll res = 0;
        while (x <= 3 and x <= xx)
            res += arcalyk[x][yy]-arcalyk[x][y-1], x += 1;
        if (x <= xx){
            while (y <= 3 and y <= yy)
                res += tarhun[xx][y]-tarhun[x-1][y], y += 1;
        }
        if (x <= xx and y <= yy){
            int a = x-y+n, b = x-yy+n, k = xx-x+1;
            swap(a, b);
            int len = b-a+1;
            b += k-1;
            k = min(k, len);
            res += cep[a] - (cep[a+k]+k*suf[a+k]);
            res += sag[b] - (sag[b-k]+k*pre[b-k]);
            a += k; b -= k;
            if (a > b)
                res -= cnt[++b] * 1LL * k;
            res += (pre[b]-pre[a-1])*1LL*k;
        }
        ans.pb(res);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6704 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6648 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 2 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 761 ms 109392 KB Output is correct
2 Correct 892 ms 109420 KB Output is correct
3 Correct 800 ms 109500 KB Output is correct
4 Correct 830 ms 109460 KB Output is correct
5 Correct 390 ms 66640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6704 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6648 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 2 ms 6480 KB Output is correct
18 Correct 73 ms 20164 KB Output is correct
19 Correct 72 ms 20396 KB Output is correct
20 Correct 76 ms 20164 KB Output is correct
21 Correct 88 ms 20172 KB Output is correct
22 Correct 73 ms 20172 KB Output is correct
23 Correct 66 ms 16780 KB Output is correct
24 Correct 63 ms 16836 KB Output is correct
25 Correct 64 ms 16836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 16060 KB Output is correct
2 Correct 750 ms 109316 KB Output is correct
3 Correct 793 ms 109500 KB Output is correct
4 Correct 799 ms 109500 KB Output is correct
5 Correct 805 ms 109528 KB Output is correct
6 Correct 814 ms 109392 KB Output is correct
7 Correct 843 ms 109632 KB Output is correct
8 Correct 822 ms 109500 KB Output is correct
9 Correct 442 ms 66172 KB Output is correct
10 Correct 427 ms 66184 KB Output is correct
11 Correct 433 ms 65988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 832 ms 109420 KB Output is correct
2 Correct 767 ms 109500 KB Output is correct
3 Correct 751 ms 109500 KB Output is correct
4 Correct 752 ms 109384 KB Output is correct
5 Correct 759 ms 109372 KB Output is correct
6 Correct 419 ms 66492 KB Output is correct
7 Correct 250 ms 44480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 761 ms 109392 KB Output is correct
2 Correct 892 ms 109420 KB Output is correct
3 Correct 800 ms 109500 KB Output is correct
4 Correct 830 ms 109460 KB Output is correct
5 Correct 390 ms 66640 KB Output is correct
6 Correct 832 ms 109420 KB Output is correct
7 Correct 767 ms 109500 KB Output is correct
8 Correct 751 ms 109500 KB Output is correct
9 Correct 752 ms 109384 KB Output is correct
10 Correct 759 ms 109372 KB Output is correct
11 Correct 419 ms 66492 KB Output is correct
12 Correct 250 ms 44480 KB Output is correct
13 Correct 847 ms 109508 KB Output is correct
14 Correct 835 ms 109448 KB Output is correct
15 Correct 848 ms 109640 KB Output is correct
16 Correct 820 ms 109448 KB Output is correct
17 Correct 828 ms 109456 KB Output is correct
18 Correct 746 ms 109500 KB Output is correct
19 Correct 315 ms 55488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6704 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 6648 KB Output is correct
17 Correct 2 ms 6480 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 761 ms 109392 KB Output is correct
20 Correct 892 ms 109420 KB Output is correct
21 Correct 800 ms 109500 KB Output is correct
22 Correct 830 ms 109460 KB Output is correct
23 Correct 390 ms 66640 KB Output is correct
24 Correct 73 ms 20164 KB Output is correct
25 Correct 72 ms 20396 KB Output is correct
26 Correct 76 ms 20164 KB Output is correct
27 Correct 88 ms 20172 KB Output is correct
28 Correct 73 ms 20172 KB Output is correct
29 Correct 66 ms 16780 KB Output is correct
30 Correct 63 ms 16836 KB Output is correct
31 Correct 64 ms 16836 KB Output is correct
32 Correct 57 ms 16060 KB Output is correct
33 Correct 750 ms 109316 KB Output is correct
34 Correct 793 ms 109500 KB Output is correct
35 Correct 799 ms 109500 KB Output is correct
36 Correct 805 ms 109528 KB Output is correct
37 Correct 814 ms 109392 KB Output is correct
38 Correct 843 ms 109632 KB Output is correct
39 Correct 822 ms 109500 KB Output is correct
40 Correct 442 ms 66172 KB Output is correct
41 Correct 427 ms 66184 KB Output is correct
42 Correct 433 ms 65988 KB Output is correct
43 Correct 832 ms 109420 KB Output is correct
44 Correct 767 ms 109500 KB Output is correct
45 Correct 751 ms 109500 KB Output is correct
46 Correct 752 ms 109384 KB Output is correct
47 Correct 759 ms 109372 KB Output is correct
48 Correct 419 ms 66492 KB Output is correct
49 Correct 250 ms 44480 KB Output is correct
50 Correct 847 ms 109508 KB Output is correct
51 Correct 835 ms 109448 KB Output is correct
52 Correct 848 ms 109640 KB Output is correct
53 Correct 820 ms 109448 KB Output is correct
54 Correct 828 ms 109456 KB Output is correct
55 Correct 746 ms 109500 KB Output is correct
56 Correct 315 ms 55488 KB Output is correct
57 Correct 757 ms 109392 KB Output is correct
58 Correct 831 ms 109300 KB Output is correct
59 Correct 841 ms 109500 KB Output is correct
60 Correct 806 ms 109500 KB Output is correct
61 Correct 836 ms 109396 KB Output is correct
62 Correct 868 ms 109500 KB Output is correct
63 Correct 413 ms 66492 KB Output is correct
64 Correct 232 ms 42252 KB Output is correct