Submission #374946

# Submission time Handle Problem Language Result Execution time Memory
374946 2021-03-08T15:50:22 Z BartolM Examination (JOI19_examination) C++17
100 / 100
246 ms 16604 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
typedef pair <pii, pii> ppp;

const int INF=0x3f3f3f3f;
const int N=100005;
const int MAX=4*N;

struct Fen{
    int F[MAX];
    Fen() {
        memset(F, 0, sizeof F);
    }
    void update(int x, int val) {
        for (x++; x<MAX; x+=x&-x) F[x]+=val;
    }
    int query(int x) {
        int ret=0;
        for (x++; x>0; x-=x&-x) ret+=F[x];
        return ret;
    }
    void reset() {
        memset(F, 0, sizeof F);
    }
};

int n, q;
pii p[N];
vector <ppp> que1, que2;
vector <int> saz;
int desaz[MAX], sol[N];
Fen xx, yy;

int cmp_zb(pii a, pii b) {
    return desaz[a.X]+desaz[a.Y]>desaz[b.X]+desaz[b.Y];
}

int cmp1(ppp a, ppp b) {
    return a.Y.X>b.Y.X;
}

void sazmi(int &x) {
    int ret=lower_bound(saz.begin(), saz.end(), x)-saz.begin();
    desaz[ret]=x;
    x=ret;
}


void solve() {
    sort(p, p+n, cmp_zb);
    sort(que1.begin(), que1.end(), cmp1);
    int ind=0;
    for (int i=0; i<=n; ++i) {
        int zbr=desaz[p[i].X]+desaz[p[i].Y];
        if (i==n) zbr=-1;
        while (ind<que1.size() && que1[ind].Y.X>zbr) {
            sol[que1[ind].Y.Y]=i-xx.query(que1[ind].X.X-1)-yy.query(que1[ind].X.Y-1);
            ind++;
        }
        xx.update(p[i].X, 1);
        yy.update(p[i].Y, 1);
    }
    sort(p, p+n); reverse(p, p+n);
    sort(que2.begin(), que2.end());
    reverse(que2.begin(), que2.end());
    yy.reset();
    ind=0;
    for (int i=0; i<=n; ++i) {
        int curr= i==n ? -1 : p[i].X;
        while (ind<que2.size() && que2[ind].X.X>curr) {
            sol[que2[ind].Y.Y]=i-yy.query(que2[ind].X.Y-1);
            ind++;
        }
        if (i<n) yy.update(p[i].Y, 1);
    }

    for (int i=0; i<q; ++i) printf("%d\n", sol[i]);
}

void load() {
    scanf("%d %d", &n, &q);
    for (int i=0; i<n; ++i) {
        scanf("%d %d", &p[i].X, &p[i].Y);
        saz.pb(p[i].X); saz.pb(p[i].Y);
    }
    for (int i=0; i<q; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);

        if (a+b<c) que1.pb({{a, b}, {c, i}});
        else que2.pb({{a, b}, {c, i}});

        saz.pb(a); saz.pb(b);
    }

    sort(saz.begin(), saz.end());
    saz.erase(unique(saz.begin(), saz.end()), saz.end());
    for (int i=0; i<n; ++i) sazmi(p[i].X), sazmi(p[i].Y);
    for (int i=0; i<que1.size(); ++i) sazmi(que1[i].X.X), sazmi(que1[i].X.Y);
    for (int i=0; i<que2.size(); ++i) sazmi(que2[i].X.X), sazmi(que2[i].X.Y);

}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

examination.cpp: In function 'void solve()':
examination.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while (ind<que1.size() && que1[ind].Y.X>zbr) {
      |                ~~~^~~~~~~~~~~~
examination.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         while (ind<que2.size() && que2[ind].X.X>curr) {
      |                ~~~^~~~~~~~~~~~
examination.cpp: In function 'void load()':
examination.cpp:110:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for (int i=0; i<que1.size(); ++i) sazmi(que1[i].X.X), sazmi(que1[i].X.Y);
      |                   ~^~~~~~~~~~~~
examination.cpp:111:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int i=0; i<que2.size(); ++i) sazmi(que2[i].X.X), sazmi(que2[i].X.Y);
      |                   ~^~~~~~~~~~~~
examination.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   92 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   94 |         scanf("%d %d", &p[i].X, &p[i].Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   99 |         scanf("%d %d %d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 2 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3436 KB Output is correct
5 Correct 2 ms 3436 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 8 ms 3840 KB Output is correct
8 Correct 9 ms 3820 KB Output is correct
9 Correct 8 ms 3820 KB Output is correct
10 Correct 7 ms 3820 KB Output is correct
11 Correct 7 ms 3820 KB Output is correct
12 Correct 6 ms 3692 KB Output is correct
13 Correct 8 ms 3948 KB Output is correct
14 Correct 8 ms 3948 KB Output is correct
15 Correct 9 ms 3948 KB Output is correct
16 Correct 7 ms 3820 KB Output is correct
17 Correct 7 ms 3840 KB Output is correct
18 Correct 5 ms 3692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 11356 KB Output is correct
2 Correct 208 ms 11376 KB Output is correct
3 Correct 209 ms 11356 KB Output is correct
4 Correct 167 ms 10588 KB Output is correct
5 Correct 180 ms 10588 KB Output is correct
6 Correct 125 ms 9564 KB Output is correct
7 Correct 208 ms 11376 KB Output is correct
8 Correct 203 ms 11356 KB Output is correct
9 Correct 197 ms 11228 KB Output is correct
10 Correct 160 ms 10332 KB Output is correct
11 Correct 161 ms 10460 KB Output is correct
12 Correct 106 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 11356 KB Output is correct
2 Correct 208 ms 11376 KB Output is correct
3 Correct 209 ms 11356 KB Output is correct
4 Correct 167 ms 10588 KB Output is correct
5 Correct 180 ms 10588 KB Output is correct
6 Correct 125 ms 9564 KB Output is correct
7 Correct 208 ms 11376 KB Output is correct
8 Correct 203 ms 11356 KB Output is correct
9 Correct 197 ms 11228 KB Output is correct
10 Correct 160 ms 10332 KB Output is correct
11 Correct 161 ms 10460 KB Output is correct
12 Correct 106 ms 9564 KB Output is correct
13 Correct 213 ms 13020 KB Output is correct
14 Correct 210 ms 13404 KB Output is correct
15 Correct 212 ms 11376 KB Output is correct
16 Correct 177 ms 12124 KB Output is correct
17 Correct 177 ms 12124 KB Output is correct
18 Correct 124 ms 11228 KB Output is correct
19 Correct 215 ms 12764 KB Output is correct
20 Correct 208 ms 12764 KB Output is correct
21 Correct 209 ms 13276 KB Output is correct
22 Correct 170 ms 10332 KB Output is correct
23 Correct 160 ms 10332 KB Output is correct
24 Correct 106 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 2 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3436 KB Output is correct
5 Correct 2 ms 3436 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 8 ms 3840 KB Output is correct
8 Correct 9 ms 3820 KB Output is correct
9 Correct 8 ms 3820 KB Output is correct
10 Correct 7 ms 3820 KB Output is correct
11 Correct 7 ms 3820 KB Output is correct
12 Correct 6 ms 3692 KB Output is correct
13 Correct 8 ms 3948 KB Output is correct
14 Correct 8 ms 3948 KB Output is correct
15 Correct 9 ms 3948 KB Output is correct
16 Correct 7 ms 3820 KB Output is correct
17 Correct 7 ms 3840 KB Output is correct
18 Correct 5 ms 3692 KB Output is correct
19 Correct 212 ms 11356 KB Output is correct
20 Correct 208 ms 11376 KB Output is correct
21 Correct 209 ms 11356 KB Output is correct
22 Correct 167 ms 10588 KB Output is correct
23 Correct 180 ms 10588 KB Output is correct
24 Correct 125 ms 9564 KB Output is correct
25 Correct 208 ms 11376 KB Output is correct
26 Correct 203 ms 11356 KB Output is correct
27 Correct 197 ms 11228 KB Output is correct
28 Correct 160 ms 10332 KB Output is correct
29 Correct 161 ms 10460 KB Output is correct
30 Correct 106 ms 9564 KB Output is correct
31 Correct 213 ms 13020 KB Output is correct
32 Correct 210 ms 13404 KB Output is correct
33 Correct 212 ms 11376 KB Output is correct
34 Correct 177 ms 12124 KB Output is correct
35 Correct 177 ms 12124 KB Output is correct
36 Correct 124 ms 11228 KB Output is correct
37 Correct 215 ms 12764 KB Output is correct
38 Correct 208 ms 12764 KB Output is correct
39 Correct 209 ms 13276 KB Output is correct
40 Correct 170 ms 10332 KB Output is correct
41 Correct 160 ms 10332 KB Output is correct
42 Correct 106 ms 9564 KB Output is correct
43 Correct 246 ms 15836 KB Output is correct
44 Correct 245 ms 16220 KB Output is correct
45 Correct 243 ms 16484 KB Output is correct
46 Correct 187 ms 13788 KB Output is correct
47 Correct 195 ms 13920 KB Output is correct
48 Correct 121 ms 10972 KB Output is correct
49 Correct 237 ms 16092 KB Output is correct
50 Correct 245 ms 16348 KB Output is correct
51 Correct 236 ms 16604 KB Output is correct
52 Correct 174 ms 13660 KB Output is correct
53 Correct 167 ms 11632 KB Output is correct