Submission #143684

# Submission time Handle Problem Language Result Execution time Memory
143684 2019-08-14T21:37:42 Z osaaateiasavtnl Examination (JOI19_examination) C++14
100 / 100
552 ms 50276 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
struct Point { int x, y; };
struct Quer { int minx, miny, minsum; };
const int N = 1e5 + 7;
int n, q;
Point a[N]; Quer d[N];
struct Q { int p, f, i; }; vector <Q> mem[2][N];
int ans[N];
void compr(vector <int> &a) { sort(all(a)); a.resize(unique(all(a)) - a.begin()); }
int lw(vector <int> &a, int x) { return lower_bound(all(a), x) - a.begin(); }
int up(vector <int> &a, int x) { return upper_bound(all(a), x) - a.begin(); }
vector <int> cx, cy, csum;
int f[N];
void clear() { for (int i = 0; i < N; ++i) f[i] = 0; }
bool upd(int i, int x, bool rev) { if (rev) i = N - i - 1; for (; i < N; i |= i + 1) f[i] += x; }
int get(int i, bool rev) { if (rev) i = N - i - 1; int ans = 0; for (; i >= 0; i &= i + 1, --i) ans += f[i]; return ans; }
vector <int> add[2][N];
void sc(vector <int> add[N], vector <Q> mem[N], bool rev) {
    clear();
    for (int i = N - 1; i >= 0; --i) {
        for (auto e : add[i]) upd(e, 1, rev);
        for (auto e : mem[i]) ans[e.i] += e.f * get(e.p, rev);
    }
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> q;
    for (int i = 0; i < n; ++i) { cin >> a[i].x >> a[i].y; cx.app(a[i].x); cy.app(a[i].y); csum.app(a[i].x + a[i].y); }
    compr(cx); compr(cy); compr(csum);
    for (int i = 0; i < n; ++i) {
        add[0][lw(cx, a[i].x)].app(lw(cy, a[i].y));
        add[1][lw(cx, a[i].x)].app(lw(csum, a[i].x + a[i].y));
    }
    for (int i = 0; i < q; ++i) {
        cin >> d[i].minx >> d[i].miny >> d[i].minsum; --d[i].minsum;
        int t = lw(cx, d[i].minx);
        mem[0][t].app({lw(cy, d[i].miny), 1, i});
        if (d[i].minsum >= d[i].minx + d[i].miny) {
            int r = up(cx, d[i].minsum - d[i].miny);
            //()()()
            mem[0][t].app({0, 1, i}); 
            mem[0][t].app({lw(cy, d[i].miny), -1, i});
            mem[0][r].app({0, -1, i});
            mem[0][r].app({lw(cy, d[i].miny), 1, i});
            mem[1][r].app({up(csum, d[i].minsum) - 1, 1, i});
            mem[1][t].app({up(csum, d[i].minsum) - 1, -1, i});
            //)()()(
        }
    }
    sc(add[0], mem[0], 1); sc(add[1], mem[1], 0);
    for (int i = 0; i < q; ++i) cout << ans[i] << '\n';
}   

Compilation message

examination.cpp: In function 'bool upd(long long int, long long int, bool)':
examination.cpp:21:97: warning: no return statement in function returning non-void [-Wreturn-type]
 bool upd(int i, int x, bool rev) { if (rev) i = N - i - 1; for (; i < N; i |= i + 1) f[i] += x; }
                                                                                                 ^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10488 KB Output is correct
2 Correct 11 ms 10492 KB Output is correct
3 Correct 11 ms 10488 KB Output is correct
4 Correct 11 ms 10616 KB Output is correct
5 Correct 11 ms 10488 KB Output is correct
6 Correct 13 ms 10624 KB Output is correct
7 Correct 23 ms 11512 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 20 ms 11472 KB Output is correct
10 Correct 18 ms 11384 KB Output is correct
11 Correct 17 ms 11384 KB Output is correct
12 Correct 15 ms 11384 KB Output is correct
13 Correct 18 ms 11256 KB Output is correct
14 Correct 18 ms 11256 KB Output is correct
15 Correct 18 ms 11256 KB Output is correct
16 Correct 15 ms 11000 KB Output is correct
17 Correct 18 ms 11512 KB Output is correct
18 Correct 13 ms 11128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 25668 KB Output is correct
2 Correct 315 ms 25720 KB Output is correct
3 Correct 337 ms 25760 KB Output is correct
4 Correct 272 ms 25688 KB Output is correct
5 Correct 172 ms 24404 KB Output is correct
6 Correct 103 ms 24664 KB Output is correct
7 Correct 267 ms 25944 KB Output is correct
8 Correct 278 ms 25816 KB Output is correct
9 Correct 256 ms 26116 KB Output is correct
10 Correct 153 ms 23032 KB Output is correct
11 Correct 223 ms 25532 KB Output is correct
12 Correct 76 ms 22508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 25668 KB Output is correct
2 Correct 315 ms 25720 KB Output is correct
3 Correct 337 ms 25760 KB Output is correct
4 Correct 272 ms 25688 KB Output is correct
5 Correct 172 ms 24404 KB Output is correct
6 Correct 103 ms 24664 KB Output is correct
7 Correct 267 ms 25944 KB Output is correct
8 Correct 278 ms 25816 KB Output is correct
9 Correct 256 ms 26116 KB Output is correct
10 Correct 153 ms 23032 KB Output is correct
11 Correct 223 ms 25532 KB Output is correct
12 Correct 76 ms 22508 KB Output is correct
13 Correct 387 ms 35032 KB Output is correct
14 Correct 328 ms 32032 KB Output is correct
15 Correct 281 ms 28324 KB Output is correct
16 Correct 336 ms 38228 KB Output is correct
17 Correct 233 ms 36176 KB Output is correct
18 Correct 141 ms 28348 KB Output is correct
19 Correct 390 ms 38024 KB Output is correct
20 Correct 440 ms 35476 KB Output is correct
21 Correct 496 ms 42836 KB Output is correct
22 Correct 160 ms 23844 KB Output is correct
23 Correct 255 ms 27240 KB Output is correct
24 Correct 83 ms 23540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10488 KB Output is correct
2 Correct 11 ms 10492 KB Output is correct
3 Correct 11 ms 10488 KB Output is correct
4 Correct 11 ms 10616 KB Output is correct
5 Correct 11 ms 10488 KB Output is correct
6 Correct 13 ms 10624 KB Output is correct
7 Correct 23 ms 11512 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 20 ms 11472 KB Output is correct
10 Correct 18 ms 11384 KB Output is correct
11 Correct 17 ms 11384 KB Output is correct
12 Correct 15 ms 11384 KB Output is correct
13 Correct 18 ms 11256 KB Output is correct
14 Correct 18 ms 11256 KB Output is correct
15 Correct 18 ms 11256 KB Output is correct
16 Correct 15 ms 11000 KB Output is correct
17 Correct 18 ms 11512 KB Output is correct
18 Correct 13 ms 11128 KB Output is correct
19 Correct 270 ms 25668 KB Output is correct
20 Correct 315 ms 25720 KB Output is correct
21 Correct 337 ms 25760 KB Output is correct
22 Correct 272 ms 25688 KB Output is correct
23 Correct 172 ms 24404 KB Output is correct
24 Correct 103 ms 24664 KB Output is correct
25 Correct 267 ms 25944 KB Output is correct
26 Correct 278 ms 25816 KB Output is correct
27 Correct 256 ms 26116 KB Output is correct
28 Correct 153 ms 23032 KB Output is correct
29 Correct 223 ms 25532 KB Output is correct
30 Correct 76 ms 22508 KB Output is correct
31 Correct 387 ms 35032 KB Output is correct
32 Correct 328 ms 32032 KB Output is correct
33 Correct 281 ms 28324 KB Output is correct
34 Correct 336 ms 38228 KB Output is correct
35 Correct 233 ms 36176 KB Output is correct
36 Correct 141 ms 28348 KB Output is correct
37 Correct 390 ms 38024 KB Output is correct
38 Correct 440 ms 35476 KB Output is correct
39 Correct 496 ms 42836 KB Output is correct
40 Correct 160 ms 23844 KB Output is correct
41 Correct 255 ms 27240 KB Output is correct
42 Correct 83 ms 23540 KB Output is correct
43 Correct 461 ms 41944 KB Output is correct
44 Correct 552 ms 41916 KB Output is correct
45 Correct 433 ms 35800 KB Output is correct
46 Correct 382 ms 41304 KB Output is correct
47 Correct 235 ms 37072 KB Output is correct
48 Correct 131 ms 39368 KB Output is correct
49 Correct 424 ms 41536 KB Output is correct
50 Correct 465 ms 46024 KB Output is correct
51 Correct 509 ms 50276 KB Output is correct
52 Correct 229 ms 34776 KB Output is correct
53 Correct 252 ms 30040 KB Output is correct