Submission #117617

# Submission time Handle Problem Language Result Execution time Memory
117617 2019-06-16T19:19:11 Z duality Two Antennas (JOI19_antennas) C++11
22 / 100
1473 ms 81056 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 ----------

int H[200000],A[200000],B[200000];
int ans[2000][2000];
vi tree[1 << 19];
vector<pair<pii,int> > tree2[1 << 19];
int update(int s,int e,int as,int ae,int i,int num) {
    if ((s > ae) || (e < as)) return 0;
    else if ((s >= as) && (e <= ae)) {
        tree[i].pb(num);
        return 0;
    }

    int mid = (s+e) / 2;
    update(s,mid,as,ae,2*i+1,num),update(mid+1,e,as,ae,2*i+2,num);
    return 0;
}
int all = -1;
int solve(int s,int e,int i) {
    if (s == e) {
        int j;
        if (s-A[s] >= 0) tree2[i].pb(mp(mp(s-B[s],s-A[s]),H[s]));
        for (j = 0; j < tree[i].size(); j++) {
            if ((tree[i][j] >= s-B[s]) && (tree[i][j] <= s-A[s])) all = max(all,abs(H[tree[i][j]]-H[s]));
        }
        return 0;
    }

    int j,mid = (s+e) / 2;
    solve(s,mid,2*i+1),solve(mid+1,e,2*i+2);
    tree2[i].resize(tree2[2*i+1].size()+tree2[2*i+2].size());
    merge(tree2[2*i+1].begin(),tree2[2*i+1].end(),tree2[2*i+2].begin(),tree2[2*i+2].end(),tree2[i].begin());
    vpii events;
    for (j = 0; j < tree2[i].size(); j++) {
        events.pb(mp(tree2[i][j].first.first,tree2[i][j].second));
        events.pb(mp(tree2[i][j].first.second+1,-tree2[i][j].second));
    }
    for (j = 0; j < tree[i].size(); j++) events.pb(mp(tree[i][j],H[tree[i][j]]+1e9));
    sort(events.begin(),events.end());
    map<int,int> M;
    for (j = 0; j < events.size(); j++) {
        if (events[j].second >= 1e9) {
            int h = events[j].second-1e9;
            if (!M.empty()) {
                all = max(all,abs(h-M.begin()->first));
                all = max(all,abs(h-(--M.end())->first));
            }
        }
        else {
            if (events[j].second > 0) {
                if (M.count(events[j].second)) M[events[j].second]++;
                else M[events[j].second] = 1;
            }
            else {
                M[-events[j].second]--;
                if (M[-events[j].second] == 0) M.erase(-events[j].second);
            }
        }
    }
    return 0;
}
int main() {
    int i;
    int N,Q;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d %d %d",&H[i],&A[i],&B[i]);
    if (0) {
        int j;
        for (i = 0; i < N; i++) {
            for (j = i+1; j < N; j++) {
                if (((j-i) >= max(A[i],A[j])) && ((j-i) <= min(B[i],B[j]))) ans[i][j] = abs(H[i]-H[j]);
                else ans[i][j] = -1;
            }
        }
        for (i = 3; i <= N; i++) {
            for (j = 0; j <= N-i; j++) ans[j][j+i-1] = max(ans[j][j+i-1],max(ans[j][j+i-2],ans[j+1][j+i-1]));
        }
        int L,R;
        scanf("%d",&Q);
        for (i = 0; i < Q; i++) {
            scanf("%d %d",&L,&R);
            printf("%d\n",ans[L-1][R-1]);
        }
        return 0;
    }

    for (i = 0; i < N; i++) update(0,N-1,i+A[i],i+B[i],0,i);
    solve(0,N-1,0);
    printf("%d\n",all);

    return 0;
}

Compilation message

antennas.cpp: In function 'int solve(int, int, int)':
antennas.cpp:78:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < tree[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~
antennas.cpp:89:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (j = 0; j < tree2[i].size(); j++) {
                 ~~^~~~~~~~~~~~~~~~~
antennas.cpp:93:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (j = 0; j < tree[i].size(); j++) events.pb(mp(tree[i][j],H[tree[i][j]]+1e9));
                 ~~^~~~~~~~~~~~~~~~
antennas.cpp:96:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (j = 0; j < events.size(); j++) {
                 ~~^~~~~~~~~~~~~~~
antennas.cpp: In function 'int main()':
antennas.cpp:120:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
antennas.cpp:121:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N; i++) scanf("%d %d %d",&H[i],&A[i],&B[i]);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:134:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&Q);
         ~~~~~^~~~~~~~~
antennas.cpp:136:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d",&L,&R);
             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 24960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 24960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1243 ms 64096 KB Output is correct
2 Correct 1393 ms 71872 KB Output is correct
3 Correct 975 ms 57512 KB Output is correct
4 Correct 1448 ms 71952 KB Output is correct
5 Correct 563 ms 45780 KB Output is correct
6 Correct 1384 ms 71920 KB Output is correct
7 Correct 1221 ms 65444 KB Output is correct
8 Correct 1425 ms 71964 KB Output is correct
9 Correct 173 ms 31700 KB Output is correct
10 Correct 1473 ms 72052 KB Output is correct
11 Correct 802 ms 53700 KB Output is correct
12 Correct 1411 ms 71960 KB Output is correct
13 Correct 715 ms 77916 KB Output is correct
14 Correct 706 ms 75204 KB Output is correct
15 Correct 581 ms 64820 KB Output is correct
16 Correct 610 ms 65992 KB Output is correct
17 Correct 840 ms 81056 KB Output is correct
18 Correct 685 ms 70348 KB Output is correct
19 Correct 630 ms 70988 KB Output is correct
20 Correct 740 ms 71724 KB Output is correct
21 Correct 738 ms 74736 KB Output is correct
22 Correct 718 ms 74412 KB Output is correct
23 Correct 678 ms 72288 KB Output is correct
24 Correct 585 ms 64964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 24960 KB Output isn't correct
2 Halted 0 ms 0 KB -