Submission #122238

# Submission time Handle Problem Language Result Execution time Memory
122238 2019-06-27T23:10:18 Z duality Examination (JOI19_examination) C++11
100 / 100
440 ms 31204 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

struct query { int A,B,C,i; };
pii s[100000];
vi a,b;
bool comp(pii a,pii b) {
    return a.first+a.second > b.first+b.second;
}
bool comp2(query a,query b) {
    return a.C > b.C;
}
query queries[100000];
int ans[100000];
vpii bit[100001];
int bit2[100001];
int main() {
    int i;
    int N,Q;
    scanf("%d %d",&N,&Q);
    for (i = 0; i < N; i++) {
        scanf("%d %d",&s[i].first,&s[i].second);
        a.pb(-s[i].first),b.pb(-s[i].second);
    }
    sort(s,s+N,comp);
    sort(a.begin(),a.end());
    a.resize(unique(a.begin(),a.end())-a.begin());
    sort(b.begin(),b.end());
    b.resize(unique(b.begin(),b.end())-b.begin());
    for (i = 0; i < Q; i++) scanf("%d %d %d",&queries[i].A,&queries[i].B,&queries[i].C),queries[i].i = i;
    sort(queries,queries+Q,comp2);

    int j = 0,k;
    for (i = 0; i < Q; i++) {
        while ((j < N) && (s[j].first+s[j].second >= queries[i].C)) {
            int x = lower_bound(a.begin(),a.end(),-s[j].first)-a.begin();
            int y = lower_bound(b.begin(),b.end(),-s[j].second)-b.begin();
            for (k = x+1; k <= a.size(); k += k & (-k)) bit[k].pb(mp(y,-1));
            j++;
        }
        int x = upper_bound(a.begin(),a.end(),-queries[i].A)-a.begin()-1;
        int y = upper_bound(b.begin(),b.end(),-queries[i].B)-b.begin()-1;
        for (k = x+1; k > 0; k -= k & (-k)) bit[k].pb(mp(y,queries[i].i));
    }
    for (i = 1; i <= a.size(); i++) {
        for (j = 0; j < bit[i].size(); j++) {
            if (bit[i][j].second == -1) {
                for (k = bit[i][j].first+1; k <= b.size(); k += k & (-k)) bit2[k]++;
            }
            else {
                for (k = bit[i][j].first+1; k > 0; k -= k & (-k)) ans[bit[i][j].second] += bit2[k];
            }
        }
        for (j = 0; j < bit[i].size(); j++) {
            if (bit[i][j].second == -1) {
                for (k = bit[i][j].first+1; k <= b.size(); k += k & (-k)) bit2[k] = 0;
            }
        }
    }
    for (i = 0; i < Q; i++) printf("%d\n",ans[i]);

    return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:92:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (k = x+1; k <= a.size(); k += k & (-k)) bit[k].pb(mp(y,-1));
                           ~~^~~~~~~~~~~
examination.cpp:99:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 1; i <= a.size(); i++) {
                 ~~^~~~~~~~~~~
examination.cpp:100:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < bit[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~
examination.cpp:102:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (k = bit[i][j].first+1; k <= b.size(); k += k & (-k)) bit2[k]++;
                                             ~~^~~~~~~~~~~
examination.cpp:108:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < bit[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~
examination.cpp:110:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (k = bit[i][j].first+1; k <= b.size(); k += k & (-k)) bit2[k] = 0;
                                             ~~^~~~~~~~~~~
examination.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&Q);
     ~~~~~^~~~~~~~~~~~~~~
examination.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&s[i].first,&s[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:84:88: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < Q; i++) scanf("%d %d %d",&queries[i].A,&queries[i].B,&queries[i].C),queries[i].i = i;
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 12 ms 3328 KB Output is correct
9 Correct 11 ms 3328 KB Output is correct
10 Correct 10 ms 3328 KB Output is correct
11 Correct 8 ms 3072 KB Output is correct
12 Correct 6 ms 3004 KB Output is correct
13 Correct 10 ms 3328 KB Output is correct
14 Correct 10 ms 3456 KB Output is correct
15 Correct 11 ms 3424 KB Output is correct
16 Correct 26 ms 2944 KB Output is correct
17 Correct 9 ms 3328 KB Output is correct
18 Correct 5 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 26204 KB Output is correct
2 Correct 293 ms 26336 KB Output is correct
3 Correct 306 ms 26084 KB Output is correct
4 Correct 228 ms 25068 KB Output is correct
5 Correct 115 ms 13276 KB Output is correct
6 Correct 79 ms 12204 KB Output is correct
7 Correct 293 ms 27652 KB Output is correct
8 Correct 306 ms 26116 KB Output is correct
9 Correct 268 ms 27648 KB Output is correct
10 Correct 100 ms 9948 KB Output is correct
11 Correct 191 ms 25076 KB Output is correct
12 Correct 56 ms 8548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 26204 KB Output is correct
2 Correct 293 ms 26336 KB Output is correct
3 Correct 306 ms 26084 KB Output is correct
4 Correct 228 ms 25068 KB Output is correct
5 Correct 115 ms 13276 KB Output is correct
6 Correct 79 ms 12204 KB Output is correct
7 Correct 293 ms 27652 KB Output is correct
8 Correct 306 ms 26116 KB Output is correct
9 Correct 268 ms 27648 KB Output is correct
10 Correct 100 ms 9948 KB Output is correct
11 Correct 191 ms 25076 KB Output is correct
12 Correct 56 ms 8548 KB Output is correct
13 Correct 324 ms 26508 KB Output is correct
14 Correct 321 ms 26456 KB Output is correct
15 Correct 287 ms 26176 KB Output is correct
16 Correct 218 ms 25312 KB Output is correct
17 Correct 130 ms 13532 KB Output is correct
18 Correct 81 ms 12264 KB Output is correct
19 Correct 318 ms 26388 KB Output is correct
20 Correct 313 ms 26344 KB Output is correct
21 Correct 310 ms 28004 KB Output is correct
22 Correct 103 ms 9820 KB Output is correct
23 Correct 197 ms 24928 KB Output is correct
24 Correct 60 ms 8424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 12 ms 3328 KB Output is correct
9 Correct 11 ms 3328 KB Output is correct
10 Correct 10 ms 3328 KB Output is correct
11 Correct 8 ms 3072 KB Output is correct
12 Correct 6 ms 3004 KB Output is correct
13 Correct 10 ms 3328 KB Output is correct
14 Correct 10 ms 3456 KB Output is correct
15 Correct 11 ms 3424 KB Output is correct
16 Correct 26 ms 2944 KB Output is correct
17 Correct 9 ms 3328 KB Output is correct
18 Correct 5 ms 2816 KB Output is correct
19 Correct 312 ms 26204 KB Output is correct
20 Correct 293 ms 26336 KB Output is correct
21 Correct 306 ms 26084 KB Output is correct
22 Correct 228 ms 25068 KB Output is correct
23 Correct 115 ms 13276 KB Output is correct
24 Correct 79 ms 12204 KB Output is correct
25 Correct 293 ms 27652 KB Output is correct
26 Correct 306 ms 26116 KB Output is correct
27 Correct 268 ms 27648 KB Output is correct
28 Correct 100 ms 9948 KB Output is correct
29 Correct 191 ms 25076 KB Output is correct
30 Correct 56 ms 8548 KB Output is correct
31 Correct 324 ms 26508 KB Output is correct
32 Correct 321 ms 26456 KB Output is correct
33 Correct 287 ms 26176 KB Output is correct
34 Correct 218 ms 25312 KB Output is correct
35 Correct 130 ms 13532 KB Output is correct
36 Correct 81 ms 12264 KB Output is correct
37 Correct 318 ms 26388 KB Output is correct
38 Correct 313 ms 26344 KB Output is correct
39 Correct 310 ms 28004 KB Output is correct
40 Correct 103 ms 9820 KB Output is correct
41 Correct 197 ms 24928 KB Output is correct
42 Correct 60 ms 8424 KB Output is correct
43 Correct 394 ms 30900 KB Output is correct
44 Correct 394 ms 30920 KB Output is correct
45 Correct 440 ms 31204 KB Output is correct
46 Correct 273 ms 29160 KB Output is correct
47 Correct 156 ms 15096 KB Output is correct
48 Correct 86 ms 12020 KB Output is correct
49 Correct 382 ms 30144 KB Output is correct
50 Correct 371 ms 31156 KB Output is correct
51 Correct 320 ms 29928 KB Output is correct
52 Correct 125 ms 11620 KB Output is correct
53 Correct 215 ms 28500 KB Output is correct