답안 #1064924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064924 2024-08-18T19:31:30 Z jerzyk Rectangles (IOI19_rect) C++17
72 / 100
1473 ms 1048576 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<12;
int drz[2 * N];

int tab[N][N];
vector<int> intr[N][N];
vector<pair<int, int>> que[N][N];
bool czy[N];
long long answer = 0;

void Add(int v, int x)
{
    v += N;
    while(v > 0)
        {drz[v] += x; v /= 2;}
}

int Query(int a, int b)
{
    a += N - 1; b += N + 1;
    int ans = 0;
    while(a / 2 != b / 2)
    {
        if(a % 2 == 0) ans += drz[a + 1];
        if(b % 2 == 1) ans += drz[b - 1];
        a /= 2; b /= 2;
    }
    return ans;
}

void CntR(int n, int m)
{
    for(int i = 1; i <= n; ++i)
    {
        vector<pair<int, int>> kol;
        for(int j = m; j >= 1; --j)
        {
            while((int)kol.size() > 0 && kol.back().st <= tab[i][j])
                kol.pop_back();
            int xd = tab[i][j];
            //cerr << "R: " << i << " " << j << "\n";
            for(int k = kol.size() - 1; k >= 0 && tab[i][j - 1] > xd; --k)
            {
                intr[i][j].pb(kol[k].nd - 1);
                //cerr << kol[k].nd - 1 << " ";
                xd = max(xd, kol[k].st);
            }
            //cout << "\n";
            kol.pb(make_pair(tab[i][j], j));
        }
    }
    for(int j = 1; j <= m; ++j)
    {
        vector<pair<int, int>> akt;
        for(int i = j; i <= m; ++i)
            akt.pb(make_pair(i, 1));
        for(int i = 1; i <= n; ++i)
        {
            vector<pair<int, int>> nxt;
            int k = 0;
            //cerr << "DP: " << i << " " << j << "\n";
            for(int l = 0; l < (int)intr[i][j].size(); ++l)
            {
                while(k < (int)akt.size() && akt[k].st < intr[i][j][l])
                    ++k;
                if(k < (int)akt.size() && akt[k].st == intr[i][j][l])
                {
                    nxt.pb(akt[k]);
                    ++k;
                }else
                    nxt.pb(make_pair(intr[i][j][l], i));

                que[i][intr[i][j][l]].pb(make_pair(j, i - nxt.back().nd + 1));
                //cerr << nxt.back().st << " " << nxt.back().nd << "\n";
            }
            akt = nxt;
            intr[i][j].clear();
        }
    }
}

void CntL(int n, int m)
{
    for(int j = 1; j <= m; ++j)
    {
        vector<pair<int, int>> kol;
        for(int i = 1; i <= n; ++i)
        {
            while((int)kol.size() > 0 && kol.back().st <= tab[i][j])
                kol.pop_back();
            int xd = tab[i][j];
            //cerr << "U: " << i << " " << j << "\n";
            for(int k = kol.size() - 1; k >= 0 && tab[i + 1][j] > xd; --k)
            {
                intr[i][j].pb(kol[k].nd + 1);
                //cerr << kol[k].nd + 1 << "\n";
                xd = max(xd, kol[k].st);
            }
            sort(intr[i][j].begin(), intr[i][j].end());
            kol.pb(make_pair(tab[i][j], i));
        }
    }
    for(int i = 1; i <= n; ++i)
    {
        vector<pair<int, int>> akt;
        for(int j = i; j <= n; ++j)
            akt.pb(make_pair(j, 1));
        for(int j = 1; j <= m; ++j)
        {
            vector<pair<int, int>> nxt;
            int k = 0;
            //cerr << "DP: " << i << " " <<  j << "\n";
            for(int l = 0; l < (int)intr[i][j].size(); ++l)
            {
                while(k < (int)akt.size() && akt[k].st < intr[i][j][l])
                    ++k;
                if(k < (int)akt.size() && akt[k].st == intr[i][j][l])
                {
                    nxt.pb(make_pair(akt[k].nd, akt[k].st));
                    ++k;
                }else
                    nxt.pb(make_pair(j, intr[i][j][l]));
                //cerr << nxt.back().nd << " " << nxt.back().st << "\n";
            }
            akt = nxt;
            sort(akt.begin(), akt.end());
            int lim = akt.size();
            k = -1;
            //cout << "QUE: " << i << " " << j << "\n";
            for(int l = 0; l < (int)que[i][j].size(); ++l)
            {
                while(k < lim - 1 && akt[k + 1].st <= que[i][j][l].st)
                {
                    ++k;
                    Add(i - akt[k].nd + 1, 1);
                }
                answer += (ll)Query(0, que[i][j][l].nd);
                //for(int r = 0; r < lim; ++r)
                    //if(akt[r].st <= que[i][j][l].st && i - akt[r].nd + 1 <= que[i][j][l].nd)
                         //++answer;
            }
            for(k = k; k >= 0; --k)
                Add(i - akt[k].nd + 1, -1);

            for(int l = 0; l < (int)akt.size(); ++l)
                swap(akt[l].st, akt[l].nd);
            sort(akt.begin(), akt.end());
            intr[i][j].clear();
        }
    }
}

long long count_rectangles(vector<vector<int>> xd)
{
    int n = xd.size(), m = xd[0].size();
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            tab[i][j] = xd[i - 1][j - 1];
    CntR(n, m);
    CntL(n, m);
    return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 788312 KB Output is correct
2 Correct 287 ms 788376 KB Output is correct
3 Correct 307 ms 788512 KB Output is correct
4 Correct 292 ms 788560 KB Output is correct
5 Correct 276 ms 788308 KB Output is correct
6 Correct 273 ms 788448 KB Output is correct
7 Correct 277 ms 788308 KB Output is correct
8 Correct 279 ms 788312 KB Output is correct
9 Correct 294 ms 788380 KB Output is correct
10 Correct 280 ms 788560 KB Output is correct
11 Correct 279 ms 788560 KB Output is correct
12 Correct 269 ms 788528 KB Output is correct
13 Correct 278 ms 788200 KB Output is correct
14 Correct 286 ms 788304 KB Output is correct
15 Correct 281 ms 788308 KB Output is correct
16 Correct 280 ms 788308 KB Output is correct
17 Correct 278 ms 788304 KB Output is correct
18 Correct 279 ms 788228 KB Output is correct
19 Correct 280 ms 788524 KB Output is correct
20 Correct 296 ms 788504 KB Output is correct
21 Correct 268 ms 788356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 788312 KB Output is correct
2 Correct 287 ms 788376 KB Output is correct
3 Correct 307 ms 788512 KB Output is correct
4 Correct 292 ms 788560 KB Output is correct
5 Correct 276 ms 788308 KB Output is correct
6 Correct 273 ms 788448 KB Output is correct
7 Correct 277 ms 788308 KB Output is correct
8 Correct 279 ms 788312 KB Output is correct
9 Correct 294 ms 788380 KB Output is correct
10 Correct 280 ms 788560 KB Output is correct
11 Correct 279 ms 788560 KB Output is correct
12 Correct 269 ms 788528 KB Output is correct
13 Correct 278 ms 788200 KB Output is correct
14 Correct 286 ms 788304 KB Output is correct
15 Correct 281 ms 788308 KB Output is correct
16 Correct 280 ms 788308 KB Output is correct
17 Correct 278 ms 788304 KB Output is correct
18 Correct 279 ms 788228 KB Output is correct
19 Correct 280 ms 788524 KB Output is correct
20 Correct 296 ms 788504 KB Output is correct
21 Correct 268 ms 788356 KB Output is correct
22 Correct 290 ms 789076 KB Output is correct
23 Correct 277 ms 789072 KB Output is correct
24 Correct 281 ms 789072 KB Output is correct
25 Correct 302 ms 788816 KB Output is correct
26 Correct 283 ms 788816 KB Output is correct
27 Correct 290 ms 788932 KB Output is correct
28 Correct 287 ms 788816 KB Output is correct
29 Correct 281 ms 788716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 788312 KB Output is correct
2 Correct 287 ms 788376 KB Output is correct
3 Correct 307 ms 788512 KB Output is correct
4 Correct 292 ms 788560 KB Output is correct
5 Correct 276 ms 788308 KB Output is correct
6 Correct 273 ms 788448 KB Output is correct
7 Correct 277 ms 788308 KB Output is correct
8 Correct 279 ms 788312 KB Output is correct
9 Correct 294 ms 788380 KB Output is correct
10 Correct 280 ms 788560 KB Output is correct
11 Correct 279 ms 788560 KB Output is correct
12 Correct 269 ms 788528 KB Output is correct
13 Correct 278 ms 788200 KB Output is correct
14 Correct 286 ms 788304 KB Output is correct
15 Correct 281 ms 788308 KB Output is correct
16 Correct 280 ms 788308 KB Output is correct
17 Correct 290 ms 789076 KB Output is correct
18 Correct 277 ms 789072 KB Output is correct
19 Correct 281 ms 789072 KB Output is correct
20 Correct 302 ms 788816 KB Output is correct
21 Correct 283 ms 788816 KB Output is correct
22 Correct 290 ms 788932 KB Output is correct
23 Correct 287 ms 788816 KB Output is correct
24 Correct 281 ms 788716 KB Output is correct
25 Correct 278 ms 788304 KB Output is correct
26 Correct 279 ms 788228 KB Output is correct
27 Correct 280 ms 788524 KB Output is correct
28 Correct 296 ms 788504 KB Output is correct
29 Correct 268 ms 788356 KB Output is correct
30 Correct 304 ms 791380 KB Output is correct
31 Correct 283 ms 791380 KB Output is correct
32 Correct 283 ms 791376 KB Output is correct
33 Correct 289 ms 790404 KB Output is correct
34 Correct 326 ms 790916 KB Output is correct
35 Correct 299 ms 791124 KB Output is correct
36 Correct 281 ms 790868 KB Output is correct
37 Correct 300 ms 790864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 788312 KB Output is correct
2 Correct 287 ms 788376 KB Output is correct
3 Correct 307 ms 788512 KB Output is correct
4 Correct 292 ms 788560 KB Output is correct
5 Correct 276 ms 788308 KB Output is correct
6 Correct 273 ms 788448 KB Output is correct
7 Correct 277 ms 788308 KB Output is correct
8 Correct 279 ms 788312 KB Output is correct
9 Correct 294 ms 788380 KB Output is correct
10 Correct 280 ms 788560 KB Output is correct
11 Correct 279 ms 788560 KB Output is correct
12 Correct 269 ms 788528 KB Output is correct
13 Correct 278 ms 788200 KB Output is correct
14 Correct 286 ms 788304 KB Output is correct
15 Correct 281 ms 788308 KB Output is correct
16 Correct 280 ms 788308 KB Output is correct
17 Correct 290 ms 789076 KB Output is correct
18 Correct 277 ms 789072 KB Output is correct
19 Correct 281 ms 789072 KB Output is correct
20 Correct 302 ms 788816 KB Output is correct
21 Correct 283 ms 788816 KB Output is correct
22 Correct 290 ms 788932 KB Output is correct
23 Correct 287 ms 788816 KB Output is correct
24 Correct 281 ms 788716 KB Output is correct
25 Correct 304 ms 791380 KB Output is correct
26 Correct 283 ms 791380 KB Output is correct
27 Correct 283 ms 791376 KB Output is correct
28 Correct 289 ms 790404 KB Output is correct
29 Correct 326 ms 790916 KB Output is correct
30 Correct 299 ms 791124 KB Output is correct
31 Correct 281 ms 790868 KB Output is correct
32 Correct 300 ms 790864 KB Output is correct
33 Correct 278 ms 788304 KB Output is correct
34 Correct 279 ms 788228 KB Output is correct
35 Correct 280 ms 788524 KB Output is correct
36 Correct 296 ms 788504 KB Output is correct
37 Correct 268 ms 788356 KB Output is correct
38 Correct 362 ms 809808 KB Output is correct
39 Correct 362 ms 806992 KB Output is correct
40 Correct 359 ms 815956 KB Output is correct
41 Correct 354 ms 814416 KB Output is correct
42 Correct 365 ms 821668 KB Output is correct
43 Correct 385 ms 821728 KB Output is correct
44 Correct 374 ms 821584 KB Output is correct
45 Correct 370 ms 819540 KB Output is correct
46 Correct 349 ms 807248 KB Output is correct
47 Correct 373 ms 810348 KB Output is correct
48 Correct 447 ms 817492 KB Output is correct
49 Correct 474 ms 817492 KB Output is correct
50 Correct 366 ms 802896 KB Output is correct
51 Correct 360 ms 802896 KB Output is correct
52 Correct 450 ms 815956 KB Output is correct
53 Correct 442 ms 815956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 788716 KB Output is correct
2 Correct 296 ms 788816 KB Output is correct
3 Correct 319 ms 788308 KB Output is correct
4 Correct 370 ms 788224 KB Output is correct
5 Correct 301 ms 788564 KB Output is correct
6 Correct 316 ms 788688 KB Output is correct
7 Correct 303 ms 788560 KB Output is correct
8 Correct 296 ms 788688 KB Output is correct
9 Correct 300 ms 788560 KB Output is correct
10 Correct 295 ms 788308 KB Output is correct
11 Correct 295 ms 788472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 788304 KB Output is correct
2 Correct 279 ms 788228 KB Output is correct
3 Correct 280 ms 788524 KB Output is correct
4 Correct 296 ms 788504 KB Output is correct
5 Correct 268 ms 788356 KB Output is correct
6 Correct 274 ms 788308 KB Output is correct
7 Correct 758 ms 881768 KB Output is correct
8 Correct 1413 ms 988648 KB Output is correct
9 Correct 1426 ms 989592 KB Output is correct
10 Correct 1473 ms 989780 KB Output is correct
11 Correct 446 ms 827472 KB Output is correct
12 Correct 592 ms 864468 KB Output is correct
13 Correct 626 ms 867664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 788312 KB Output is correct
2 Correct 287 ms 788376 KB Output is correct
3 Correct 307 ms 788512 KB Output is correct
4 Correct 292 ms 788560 KB Output is correct
5 Correct 276 ms 788308 KB Output is correct
6 Correct 273 ms 788448 KB Output is correct
7 Correct 277 ms 788308 KB Output is correct
8 Correct 279 ms 788312 KB Output is correct
9 Correct 294 ms 788380 KB Output is correct
10 Correct 280 ms 788560 KB Output is correct
11 Correct 279 ms 788560 KB Output is correct
12 Correct 269 ms 788528 KB Output is correct
13 Correct 278 ms 788200 KB Output is correct
14 Correct 286 ms 788304 KB Output is correct
15 Correct 281 ms 788308 KB Output is correct
16 Correct 280 ms 788308 KB Output is correct
17 Correct 290 ms 789076 KB Output is correct
18 Correct 277 ms 789072 KB Output is correct
19 Correct 281 ms 789072 KB Output is correct
20 Correct 302 ms 788816 KB Output is correct
21 Correct 283 ms 788816 KB Output is correct
22 Correct 290 ms 788932 KB Output is correct
23 Correct 287 ms 788816 KB Output is correct
24 Correct 281 ms 788716 KB Output is correct
25 Correct 304 ms 791380 KB Output is correct
26 Correct 283 ms 791380 KB Output is correct
27 Correct 283 ms 791376 KB Output is correct
28 Correct 289 ms 790404 KB Output is correct
29 Correct 326 ms 790916 KB Output is correct
30 Correct 299 ms 791124 KB Output is correct
31 Correct 281 ms 790868 KB Output is correct
32 Correct 300 ms 790864 KB Output is correct
33 Correct 362 ms 809808 KB Output is correct
34 Correct 362 ms 806992 KB Output is correct
35 Correct 359 ms 815956 KB Output is correct
36 Correct 354 ms 814416 KB Output is correct
37 Correct 365 ms 821668 KB Output is correct
38 Correct 385 ms 821728 KB Output is correct
39 Correct 374 ms 821584 KB Output is correct
40 Correct 370 ms 819540 KB Output is correct
41 Correct 349 ms 807248 KB Output is correct
42 Correct 373 ms 810348 KB Output is correct
43 Correct 447 ms 817492 KB Output is correct
44 Correct 474 ms 817492 KB Output is correct
45 Correct 366 ms 802896 KB Output is correct
46 Correct 360 ms 802896 KB Output is correct
47 Correct 450 ms 815956 KB Output is correct
48 Correct 442 ms 815956 KB Output is correct
49 Correct 305 ms 788716 KB Output is correct
50 Correct 296 ms 788816 KB Output is correct
51 Correct 319 ms 788308 KB Output is correct
52 Correct 370 ms 788224 KB Output is correct
53 Correct 301 ms 788564 KB Output is correct
54 Correct 316 ms 788688 KB Output is correct
55 Correct 303 ms 788560 KB Output is correct
56 Correct 296 ms 788688 KB Output is correct
57 Correct 300 ms 788560 KB Output is correct
58 Correct 295 ms 788308 KB Output is correct
59 Correct 295 ms 788472 KB Output is correct
60 Correct 274 ms 788308 KB Output is correct
61 Correct 758 ms 881768 KB Output is correct
62 Correct 1413 ms 988648 KB Output is correct
63 Correct 1426 ms 989592 KB Output is correct
64 Correct 1473 ms 989780 KB Output is correct
65 Correct 446 ms 827472 KB Output is correct
66 Correct 592 ms 864468 KB Output is correct
67 Correct 626 ms 867664 KB Output is correct
68 Correct 278 ms 788304 KB Output is correct
69 Correct 279 ms 788228 KB Output is correct
70 Correct 280 ms 788524 KB Output is correct
71 Correct 296 ms 788504 KB Output is correct
72 Correct 268 ms 788356 KB Output is correct
73 Correct 1394 ms 1017172 KB Output is correct
74 Correct 1188 ms 983664 KB Output is correct
75 Runtime error 1047 ms 1048576 KB Execution killed with signal 9
76 Halted 0 ms 0 KB -