Submission #889565

# Submission time Handle Problem Language Result Execution time Memory
889565 2023-12-20T02:36:15 Z vjudge1 Rectangles (IOI19_rect) C++17
37 / 100
5000 ms 82844 KB
#include <bits/stdc++.h>
#include "rect.h"
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
 
 
using namespace std;
 
using vi = vector<int>;
using i4 = array<int, 4>;
using vi4 = vector<i4>;
 
void extract(int n, int m, vector<vi> &V, vi4 &V1) {
    vector<stack<int> > lin(m);
    for(int j = 0; j < m; ++j)
        lin[j].push(0);
    set<int> Cur;
    for(int i = 1; i < n; ++i) {
        vector<pair<int, int> > Ult, UrmU; /// perechi (linie, j din trecut)
        for(int j = 0; j < m; ++j) {
            Cur.clear();
            int uv = V[i][j];
            while(!lin[j].empty() && V[i][j] > V[lin[j].top()][j]) {
                if(V[lin[j].top()][j] != uv) {
                    Cur.insert(lin[j].top());
                    uv = V[lin[j].top()][j];
                }
                lin[j].pop();
            }
            if(!lin[j].empty()) {
                if(V[lin[j].top()][j] != uv) { // desc
                    Cur.insert(lin[j].top());
                    uv = V[lin[j].top()][j];
                }
            }
            lin[j].push(i);
            UrmU.clear();
            for(auto [l, jv] : Ult) {
                if(Cur.count(l)) {
                    UrmU.push_back({l, jv});
                    Cur.erase(l);
                } else {
                    if(abs(l - i) > 1 && j - 1 - jv >= 0)
                        V1.push_back(i4{l, i, jv, j - 1});
                }
            }
            swap(Ult, UrmU);
            for(auto vc : Cur)
                Ult.push_back({vc, j});
        }
        for(auto [l, jv] : Ult) {
            if(abs(l - i) > 1 && m - 1 - jv >= 0)
                V1.push_back(i4{l, i, jv, m - 1});
        }
    }
}
 
struct CEVA {
    int MAX_V = 14000002;
    int CMAGIC = 7000001;
 
    vector<tuple<int, int, int> > VQ;
    vector<int> V;
 
    void fake_update(int v1, int v2, int v3) {
        v1 += CMAGIC;
        v2 += CMAGIC;
        v3 += CMAGIC;
        while(v1 < MAX_V) {
            int a = v2;
            while(a < MAX_V) {
                int b = v3;
                while(b < MAX_V) {
                    VQ.push_back({v1, a, b});
                    b += b & -b;
                }
                a += a & -a;
            }
            v1 += v1 & -v1;
        }
    }
 
    void init() {
        sort(VQ.begin(), VQ.end());
        VQ.resize(unique(VQ.begin(), VQ.end()) - VQ.begin());
        V.assign(VQ.size(), 0);
    }
 
    int id(tuple<int, int, int> q) {
        int p = lower_bound(VQ.begin(), VQ.end(), 
                q) - VQ.begin();
        if(VQ[p] != q) p = -1;
        return p;
    }
 
    void update(int v1, int v2, int v3) {
        v1 += CMAGIC;
        v2 += CMAGIC;
        v3 += CMAGIC;
        while(v1 < MAX_V) {
            int a = v2;
            while(a < MAX_V) {
                int b = v3;
                while(b < MAX_V) {
                    V[id({v1, a, b})] += 1;
                    b += b & -b;
                }
                a += a & -a;
            }
            v1 += v1 & -v1;
        }
    }
 
    int query(int v1, int v2, int v3) {
        v1 += CMAGIC;
        v2 += CMAGIC;
        v3 += CMAGIC;
        int re = 0;
        while(v1) {
            int a = v2;
            while(a) {
                int b = v3;
                while(b) {
                    int p = id({v1, a, b});
                    if(p != -1) re += V[p];
                    b -= b & -b;
                }
                a -= a & -a;
            }
            v1 -= v1 & -v1;
        }
        return re;
    }
};
 
long long count_rectangles(std::vector<std::vector<int> > V) {
    int n = V.size(), m = V[0].size();
    vector<vi> VT(m, vi(n, 0));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j) 
            VT[j][i] = V[i][j];
 
    vi4 V1, V2;
 
    extract(n, m, V, V1);
    extract(m, n, VT, V2);
    for(auto &it : V2) {
        swap(it[0], it[2]);
        swap(it[1], it[3]);
    }
 
    for(auto &it : V1) {
        ++it[0];
        --it[1];
    }
 
    for(auto &it : V2) {
        ++it[2];
        --it[3];
    }
 
 
    for(auto &it : V1) {
        it[0] *= -1;
        it[3] *= -1;
    }
    for(auto &it : V2) {
        it[0] *= -1;
        it[3] *= -1;
    }

    using i3 = array<int, 3>;
 
    sort(V1.begin(), V1.end(), [&](auto a, auto b) {
            return a[0] < b[0];
    });
    sort(V2.begin(), V2.end(), [&](auto a, auto b) {
            return a[0] < b[0];
    });
    int p = 0;
    vector<i3> W;
    long long re = 0;
    for(auto it : V2) {
        while(p < V1.size() && V1[p][0] <= it[0]) {
            W.push_back(i3{V1[p][1], V1[p][2], V1[p][3]});
            ++p;
        }
        for(auto it2 : W) {
            int ok = 1;
            for(int i = 0; i < 3; ++i)
                ok &= it[i + 1] >= it2[i];
            re += ok;
        }
    }
	return re;
}

Compilation message

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:186:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  186 |         while(p < V1.size() && V1[p][0] <= it[0]) {
      |               ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 1 ms 432 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 1 ms 432 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 856 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 13 ms 884 KB Output is correct
27 Correct 12 ms 860 KB Output is correct
28 Correct 10 ms 860 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 13 ms 884 KB Output is correct
22 Correct 12 ms 860 KB Output is correct
23 Correct 10 ms 860 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 0 ms 432 KB Output is correct
26 Correct 1 ms 432 KB Output is correct
27 Correct 1 ms 436 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 17 ms 1372 KB Output is correct
31 Correct 18 ms 1372 KB Output is correct
32 Correct 17 ms 1464 KB Output is correct
33 Correct 95 ms 1756 KB Output is correct
34 Correct 430 ms 2820 KB Output is correct
35 Correct 426 ms 2988 KB Output is correct
36 Correct 286 ms 2692 KB Output is correct
37 Correct 281 ms 2708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 13 ms 884 KB Output is correct
22 Correct 12 ms 860 KB Output is correct
23 Correct 10 ms 860 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 17 ms 1372 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
27 Correct 17 ms 1464 KB Output is correct
28 Correct 95 ms 1756 KB Output is correct
29 Correct 430 ms 2820 KB Output is correct
30 Correct 426 ms 2988 KB Output is correct
31 Correct 286 ms 2692 KB Output is correct
32 Correct 281 ms 2708 KB Output is correct
33 Correct 0 ms 432 KB Output is correct
34 Correct 1 ms 432 KB Output is correct
35 Correct 1 ms 436 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 5092 ms 21304 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 3 ms 1884 KB Output is correct
3 Correct 2 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 2392 KB Output is correct
6 Correct 6 ms 2396 KB Output is correct
7 Correct 6 ms 2396 KB Output is correct
8 Correct 6 ms 2136 KB Output is correct
9 Correct 5 ms 2392 KB Output is correct
10 Correct 2 ms 2140 KB Output is correct
11 Correct 3 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Execution timed out 5045 ms 82844 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 13 ms 884 KB Output is correct
22 Correct 12 ms 860 KB Output is correct
23 Correct 10 ms 860 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 17 ms 1372 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
27 Correct 17 ms 1464 KB Output is correct
28 Correct 95 ms 1756 KB Output is correct
29 Correct 430 ms 2820 KB Output is correct
30 Correct 426 ms 2988 KB Output is correct
31 Correct 286 ms 2692 KB Output is correct
32 Correct 281 ms 2708 KB Output is correct
33 Execution timed out 5092 ms 21304 KB Time limit exceeded
34 Halted 0 ms 0 KB -