Submission #59734

# Submission time Handle Problem Language Result Execution time Memory
59734 2018-07-23T01:07:58 Z duality Land of the Rainbow Gold (APIO17_rainbow) C++11
100 / 100
2166 ms 195256 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 ----------
#include "rainbow.h"

int r,c;
int lx,rx,ly,ry;
vi tree[4][1 << 19];
int sorted[4][1 << 19];
int update(int s,int e,int ay,int ax,int i,int t) {
    if ((s > ay) || (e < ay)) return 0;
    else if (s == e) {
        tree[t][i].pb(ax);
        return 0;
    }

    int mid = (s+e) / 2;
    update(s,mid,ay,ax,2*i+1,t);
    update(mid+1,e,ay,ax,2*i+2,t);
    tree[t][i].pb(ax);
    return 0;
}
int query(int s,int e,int qys,int qye,int qxs,int qxe,int i,int t) {
    if ((qys > qye) || (qxs > qxe)) return 0;
    else if ((s > qye) || (e < qys)) return 0;
    else if ((s >= qys) && (e <= qye)) {
        if (!sorted[t][i]) sort(tree[t][i].begin(),tree[t][i].end()),sorted[t][i] = 1;
        return upper_bound(tree[t][i].begin(),tree[t][i].end(),qxe) \
             - lower_bound(tree[t][i].begin(),tree[t][i].end(),qxs);
    }

    int mid = (s+e) / 2;
    return query(s,mid,qys,qye,qxs,qxe,2*i+1,t)+query(mid+1,e,qys,qye,qxs,qxe,2*i+2,t);
}
vpii p1,p2,p3,p4;
void init(int R,int C,int sr,int sc,int M,char *S) {
    int i;
    r = R,c = C;
    sr--,sc--;
    lx = rx = sc,ly = ry = sr;
    p1.pb(mp(sr+1,sc+1));
    p2.pb(mp(sr+1,sc+1)),p2.pb(mp(sr,sc+1));
    p3.pb(mp(sr+1,sc+1)),p3.pb(mp(sr+1,sc));
    p4.pb(mp(sr+1,sc+1)),p4.pb(mp(sr,sc+1)),p4.pb(mp(sr+1,sc)),p4.pb(mp(sr,sc));
    for (i = 0; i < M; i++) {
        if (S[i] == 'N') sr--;
        else if (S[i] == 'S') sr++;
        else if (S[i] == 'W') sc--;
        else sc++;
        lx = min(lx,sc),rx = max(rx,sc);
        ly = min(ly,sr),ry = max(ry,sr);
        p1.pb(mp(sr+1,sc+1));
        p2.pb(mp(sr+1,sc+1)),p2.pb(mp(sr,sc+1));
        p3.pb(mp(sr+1,sc+1)),p3.pb(mp(sr+1,sc));
        p4.pb(mp(sr+1,sc+1)),p4.pb(mp(sr,sc+1)),p4.pb(mp(sr+1,sc)),p4.pb(mp(sr,sc));
    }
    sort(p1.begin(),p1.end());
    p1.resize(unique(p1.begin(),p1.end())-p1.begin());
    sort(p2.begin(),p2.end());
    p2.resize(unique(p2.begin(),p2.end())-p2.begin());
    sort(p3.begin(),p3.end());
    p3.resize(unique(p3.begin(),p3.end())-p3.begin());
    sort(p4.begin(),p4.end());
    p4.resize(unique(p4.begin(),p4.end())-p4.begin());
    for (i = 0; i < p1.size(); i++) update(0,r,p1[i].first,p1[i].second,0,0);
    for (i = 0; i < p2.size(); i++) update(0,r,p2[i].first,p2[i].second,0,1);
    for (i = 0; i < p3.size(); i++) update(0,r,p3[i].first,p3[i].second,0,2);
    for (i = 0; i < p4.size(); i++) update(0,r,p4[i].first,p4[i].second,0,3);
}

int colour(int ar,int ac,int br,int bc) {
    ar--,ac--,br--,bc--;
    LLI ans = 0;
    ans += (LLI) (br-ar+1)*(bc-ac+1)-query(0,r,ar+1,br+1,ac+1,bc+1,0,0);
    ans -= (LLI) (br-ar)*(bc-ac+1)-query(0,r,ar+1,br,ac+1,bc+1,0,1);
    ans -= (LLI) (br-ar+1)*(bc-ac)-query(0,r,ar+1,br+1,ac+1,bc,0,2);
    ans += (LLI) (br-ar)*(bc-ac)-query(0,r,ar+1,br,ac+1,bc,0,3);
    if ((ar < ly) && (br > ry) && (ac < lx) && (bc > rx)) ans++;
    return ans;
}

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:118:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < p1.size(); i++) update(0,r,p1[i].first,p1[i].second,0,0);
                 ~~^~~~~~~~~~~
rainbow.cpp:119:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < p2.size(); i++) update(0,r,p2[i].first,p2[i].second,0,1);
                 ~~^~~~~~~~~~~
rainbow.cpp:120:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < p3.size(); i++) update(0,r,p3[i].first,p3[i].second,0,2);
                 ~~^~~~~~~~~~~
rainbow.cpp:121:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < p4.size(); i++) update(0,r,p4[i].first,p4[i].second,0,3);
                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 54 ms 49656 KB Output is correct
2 Correct 70 ms 50048 KB Output is correct
3 Correct 59 ms 50048 KB Output is correct
4 Correct 80 ms 50048 KB Output is correct
5 Correct 94 ms 50320 KB Output is correct
6 Correct 51 ms 50320 KB Output is correct
7 Correct 57 ms 50320 KB Output is correct
8 Correct 53 ms 50320 KB Output is correct
9 Correct 55 ms 50320 KB Output is correct
10 Correct 51 ms 50320 KB Output is correct
11 Correct 70 ms 50320 KB Output is correct
12 Correct 68 ms 50424 KB Output is correct
13 Correct 66 ms 50548 KB Output is correct
14 Correct 63 ms 50840 KB Output is correct
15 Correct 55 ms 50840 KB Output is correct
16 Correct 51 ms 50840 KB Output is correct
17 Correct 49 ms 50840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 50840 KB Output is correct
2 Correct 49 ms 50840 KB Output is correct
3 Correct 281 ms 62880 KB Output is correct
4 Correct 403 ms 72472 KB Output is correct
5 Correct 372 ms 75328 KB Output is correct
6 Correct 372 ms 76056 KB Output is correct
7 Correct 425 ms 77020 KB Output is correct
8 Correct 220 ms 77020 KB Output is correct
9 Correct 425 ms 79488 KB Output is correct
10 Correct 362 ms 79488 KB Output is correct
11 Correct 416 ms 79488 KB Output is correct
12 Correct 314 ms 79488 KB Output is correct
13 Correct 281 ms 79488 KB Output is correct
14 Correct 295 ms 79488 KB Output is correct
15 Correct 272 ms 79488 KB Output is correct
16 Correct 386 ms 79488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 50840 KB Output is correct
2 Correct 394 ms 122216 KB Output is correct
3 Correct 757 ms 140316 KB Output is correct
4 Correct 522 ms 140316 KB Output is correct
5 Correct 401 ms 140316 KB Output is correct
6 Correct 227 ms 140316 KB Output is correct
7 Correct 279 ms 140316 KB Output is correct
8 Correct 190 ms 140316 KB Output is correct
9 Correct 187 ms 140316 KB Output is correct
10 Correct 181 ms 140316 KB Output is correct
11 Correct 304 ms 140316 KB Output is correct
12 Correct 525 ms 140316 KB Output is correct
13 Correct 684 ms 141524 KB Output is correct
14 Correct 544 ms 141524 KB Output is correct
15 Correct 470 ms 141524 KB Output is correct
16 Correct 189 ms 141524 KB Output is correct
17 Correct 248 ms 141524 KB Output is correct
18 Correct 427 ms 141524 KB Output is correct
19 Correct 531 ms 141524 KB Output is correct
20 Correct 523 ms 141524 KB Output is correct
21 Correct 219 ms 141524 KB Output is correct
22 Correct 195 ms 141524 KB Output is correct
23 Correct 161 ms 141524 KB Output is correct
24 Correct 337 ms 141524 KB Output is correct
25 Correct 474 ms 141524 KB Output is correct
26 Correct 768 ms 142700 KB Output is correct
27 Correct 566 ms 142700 KB Output is correct
28 Correct 467 ms 142700 KB Output is correct
29 Correct 202 ms 142700 KB Output is correct
30 Correct 279 ms 142700 KB Output is correct
31 Correct 397 ms 142700 KB Output is correct
32 Correct 448 ms 142700 KB Output is correct
33 Correct 444 ms 142700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 49656 KB Output is correct
2 Correct 70 ms 50048 KB Output is correct
3 Correct 59 ms 50048 KB Output is correct
4 Correct 80 ms 50048 KB Output is correct
5 Correct 94 ms 50320 KB Output is correct
6 Correct 51 ms 50320 KB Output is correct
7 Correct 57 ms 50320 KB Output is correct
8 Correct 53 ms 50320 KB Output is correct
9 Correct 55 ms 50320 KB Output is correct
10 Correct 51 ms 50320 KB Output is correct
11 Correct 70 ms 50320 KB Output is correct
12 Correct 68 ms 50424 KB Output is correct
13 Correct 66 ms 50548 KB Output is correct
14 Correct 63 ms 50840 KB Output is correct
15 Correct 55 ms 50840 KB Output is correct
16 Correct 51 ms 50840 KB Output is correct
17 Correct 49 ms 50840 KB Output is correct
18 Correct 1713 ms 142700 KB Output is correct
19 Correct 298 ms 142700 KB Output is correct
20 Correct 282 ms 142700 KB Output is correct
21 Correct 279 ms 142700 KB Output is correct
22 Correct 359 ms 142700 KB Output is correct
23 Correct 278 ms 142700 KB Output is correct
24 Correct 389 ms 142700 KB Output is correct
25 Correct 344 ms 142700 KB Output is correct
26 Correct 461 ms 142700 KB Output is correct
27 Correct 1004 ms 142700 KB Output is correct
28 Correct 808 ms 142700 KB Output is correct
29 Correct 919 ms 142700 KB Output is correct
30 Correct 1533 ms 142700 KB Output is correct
31 Correct 63 ms 142700 KB Output is correct
32 Correct 1252 ms 142700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 49656 KB Output is correct
2 Correct 70 ms 50048 KB Output is correct
3 Correct 59 ms 50048 KB Output is correct
4 Correct 80 ms 50048 KB Output is correct
5 Correct 94 ms 50320 KB Output is correct
6 Correct 51 ms 50320 KB Output is correct
7 Correct 57 ms 50320 KB Output is correct
8 Correct 53 ms 50320 KB Output is correct
9 Correct 55 ms 50320 KB Output is correct
10 Correct 51 ms 50320 KB Output is correct
11 Correct 70 ms 50320 KB Output is correct
12 Correct 68 ms 50424 KB Output is correct
13 Correct 66 ms 50548 KB Output is correct
14 Correct 63 ms 50840 KB Output is correct
15 Correct 55 ms 50840 KB Output is correct
16 Correct 51 ms 50840 KB Output is correct
17 Correct 49 ms 50840 KB Output is correct
18 Correct 1713 ms 142700 KB Output is correct
19 Correct 298 ms 142700 KB Output is correct
20 Correct 282 ms 142700 KB Output is correct
21 Correct 279 ms 142700 KB Output is correct
22 Correct 359 ms 142700 KB Output is correct
23 Correct 278 ms 142700 KB Output is correct
24 Correct 389 ms 142700 KB Output is correct
25 Correct 344 ms 142700 KB Output is correct
26 Correct 461 ms 142700 KB Output is correct
27 Correct 1004 ms 142700 KB Output is correct
28 Correct 808 ms 142700 KB Output is correct
29 Correct 919 ms 142700 KB Output is correct
30 Correct 1533 ms 142700 KB Output is correct
31 Correct 63 ms 142700 KB Output is correct
32 Correct 1252 ms 142700 KB Output is correct
33 Correct 394 ms 122216 KB Output is correct
34 Correct 757 ms 140316 KB Output is correct
35 Correct 522 ms 140316 KB Output is correct
36 Correct 401 ms 140316 KB Output is correct
37 Correct 227 ms 140316 KB Output is correct
38 Correct 279 ms 140316 KB Output is correct
39 Correct 190 ms 140316 KB Output is correct
40 Correct 187 ms 140316 KB Output is correct
41 Correct 181 ms 140316 KB Output is correct
42 Correct 304 ms 140316 KB Output is correct
43 Correct 525 ms 140316 KB Output is correct
44 Correct 684 ms 141524 KB Output is correct
45 Correct 544 ms 141524 KB Output is correct
46 Correct 470 ms 141524 KB Output is correct
47 Correct 189 ms 141524 KB Output is correct
48 Correct 248 ms 141524 KB Output is correct
49 Correct 427 ms 141524 KB Output is correct
50 Correct 531 ms 141524 KB Output is correct
51 Correct 523 ms 141524 KB Output is correct
52 Correct 219 ms 141524 KB Output is correct
53 Correct 195 ms 141524 KB Output is correct
54 Correct 161 ms 141524 KB Output is correct
55 Correct 337 ms 141524 KB Output is correct
56 Correct 474 ms 141524 KB Output is correct
57 Correct 768 ms 142700 KB Output is correct
58 Correct 566 ms 142700 KB Output is correct
59 Correct 467 ms 142700 KB Output is correct
60 Correct 202 ms 142700 KB Output is correct
61 Correct 279 ms 142700 KB Output is correct
62 Correct 397 ms 142700 KB Output is correct
63 Correct 448 ms 142700 KB Output is correct
64 Correct 444 ms 142700 KB Output is correct
65 Correct 547 ms 142700 KB Output is correct
66 Correct 685 ms 142700 KB Output is correct
67 Correct 592 ms 142700 KB Output is correct
68 Correct 975 ms 142700 KB Output is correct
69 Correct 1912 ms 161936 KB Output is correct
70 Correct 2166 ms 183148 KB Output is correct
71 Correct 1803 ms 183148 KB Output is correct
72 Correct 1703 ms 183148 KB Output is correct
73 Correct 1034 ms 183148 KB Output is correct
74 Correct 1092 ms 183148 KB Output is correct
75 Correct 1149 ms 183148 KB Output is correct
76 Correct 2141 ms 192280 KB Output is correct
77 Correct 1938 ms 195256 KB Output is correct
78 Correct 281 ms 62880 KB Output is correct
79 Correct 403 ms 72472 KB Output is correct
80 Correct 372 ms 75328 KB Output is correct
81 Correct 372 ms 76056 KB Output is correct
82 Correct 425 ms 77020 KB Output is correct
83 Correct 220 ms 77020 KB Output is correct
84 Correct 425 ms 79488 KB Output is correct
85 Correct 362 ms 79488 KB Output is correct
86 Correct 416 ms 79488 KB Output is correct
87 Correct 314 ms 79488 KB Output is correct
88 Correct 281 ms 79488 KB Output is correct
89 Correct 295 ms 79488 KB Output is correct
90 Correct 272 ms 79488 KB Output is correct
91 Correct 386 ms 79488 KB Output is correct