Submission #233193

# Submission time Handle Problem Language Result Execution time Memory
233193 2020-05-19T21:13:14 Z duality Treatment Project (JOI20_treatment) C++11
100 / 100
1209 ms 174760 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 pro { int t,l,r,c; };
bool comp(pro a,pro b) {
    return a.t < b.t;
}
pro p[100000];
vpii adjList[3000000];
pii sorted[100000];
int bit[100001],num;
LLI dist[3000000];
priority_queue<pair<LLI,int> > H;
int main() {
    int i;
    int N,M;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) scanf("%d %d %d %d",&p[i].t,&p[i].l,&p[i].r,&p[i].c),p[i].l--,p[i].r--;
    sort(p,p+M,comp);

    int j;
    for (i = 0; i < M; i++) {
        if (p[i].l == 0) adjList[0].pb(mp(i+2,p[i].c));
        if (p[i].r == N-1) adjList[i+2].pb(mp(1,0));
        sorted[i] = mp(p[i].l-p[i].t,i);
    }
    num = M+2;
    sort(sorted,sorted+M);
    for (i = 1; i <= M; i++) bit[i] = num++;
    for (i = 0; i < M; i++) {
        int x = lower_bound(sorted,sorted+M,mp(p[i].l-p[i].t,i))-sorted;
        for (j = x+1; j <= M; j += j & (-j)) {
            adjList[num].pb(mp(bit[j],0)),adjList[num].pb(mp(i+2,p[i].c));
            bit[j] = num++;
        }
        x = upper_bound(sorted,sorted+M,mp(p[i].r-p[i].t+1,M))-sorted-1;
        for (j = x+1; j > 0; j -= j & (-j)) adjList[i+2].pb(mp(bit[j],0));
    }
    for (i = 0; i < M; i++) sorted[i] = mp(p[i].l+p[i].t,i);
    sort(sorted,sorted+M);
    for (i = 1; i <= M; i++) bit[i] = num++;
    for (i = M-1; i >= 0; i--) {
        int x = lower_bound(sorted,sorted+M,mp(p[i].l+p[i].t,i))-sorted;
        for (j = x+1; j <= M; j += j & (-j)) {
            adjList[num].pb(mp(bit[j],0)),adjList[num].pb(mp(i+2,p[i].c));
            bit[j] = num++;
        }
        x = upper_bound(sorted,sorted+M,mp(p[i].r+p[i].t+1,M))-sorted-1;
        for (j = x+1; j > 0; j -= j & (-j)) adjList[i+2].pb(mp(bit[j],0));
    }

    for (i = 0; i < num; i++) dist[i] = -1;
    dist[0] = 0,H.push(mp(0,0));
    while (!H.empty()) {
        int u = H.top().second;
        LLI d = -H.top().first;
        H.pop();

        if (d > dist[u]) continue;
        for (i = 0; i < adjList[u].size(); i++) {
            int v = adjList[u][i].first;
            if ((dist[v] == -1) || (dist[u]+adjList[u][i].second < dist[v])) {
                dist[v] = dist[u]+adjList[u][i].second;
                H.push(mp(-dist[v],v));
            }
        }
    }
    printf("%lld\n",dist[1]);

    return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:114:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
treatment.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
treatment.cpp:72:90: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < M; i++) scanf("%d %d %d %d",&p[i].t,&p[i].l,&p[i].r,&p[i].c),p[i].l--,p[i].r--;
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 801 ms 166008 KB Output is correct
2 Correct 564 ms 168544 KB Output is correct
3 Correct 736 ms 166768 KB Output is correct
4 Correct 737 ms 166260 KB Output is correct
5 Correct 699 ms 167020 KB Output is correct
6 Correct 675 ms 165788 KB Output is correct
7 Correct 620 ms 167032 KB Output is correct
8 Correct 389 ms 164828 KB Output is correct
9 Correct 384 ms 165624 KB Output is correct
10 Correct 383 ms 167032 KB Output is correct
11 Correct 1130 ms 168560 KB Output is correct
12 Correct 1120 ms 168604 KB Output is correct
13 Correct 1153 ms 170628 KB Output is correct
14 Correct 1158 ms 170740 KB Output is correct
15 Correct 954 ms 168568 KB Output is correct
16 Correct 967 ms 168696 KB Output is correct
17 Correct 949 ms 167772 KB Output is correct
18 Correct 1050 ms 168052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 70776 KB Output is correct
2 Correct 46 ms 70776 KB Output is correct
3 Correct 45 ms 70776 KB Output is correct
4 Correct 48 ms 70776 KB Output is correct
5 Correct 46 ms 70776 KB Output is correct
6 Correct 45 ms 70776 KB Output is correct
7 Correct 45 ms 70776 KB Output is correct
8 Correct 45 ms 70784 KB Output is correct
9 Correct 45 ms 70776 KB Output is correct
10 Correct 45 ms 70784 KB Output is correct
11 Correct 45 ms 70784 KB Output is correct
12 Correct 45 ms 70784 KB Output is correct
13 Correct 45 ms 70776 KB Output is correct
14 Correct 45 ms 70780 KB Output is correct
15 Correct 45 ms 70784 KB Output is correct
16 Correct 45 ms 70776 KB Output is correct
17 Correct 46 ms 70776 KB Output is correct
18 Correct 45 ms 70776 KB Output is correct
19 Correct 45 ms 70776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 70776 KB Output is correct
2 Correct 46 ms 70776 KB Output is correct
3 Correct 45 ms 70776 KB Output is correct
4 Correct 48 ms 70776 KB Output is correct
5 Correct 46 ms 70776 KB Output is correct
6 Correct 45 ms 70776 KB Output is correct
7 Correct 45 ms 70776 KB Output is correct
8 Correct 45 ms 70784 KB Output is correct
9 Correct 45 ms 70776 KB Output is correct
10 Correct 45 ms 70784 KB Output is correct
11 Correct 45 ms 70784 KB Output is correct
12 Correct 45 ms 70784 KB Output is correct
13 Correct 45 ms 70776 KB Output is correct
14 Correct 45 ms 70780 KB Output is correct
15 Correct 45 ms 70784 KB Output is correct
16 Correct 45 ms 70776 KB Output is correct
17 Correct 46 ms 70776 KB Output is correct
18 Correct 45 ms 70776 KB Output is correct
19 Correct 45 ms 70776 KB Output is correct
20 Correct 63 ms 74616 KB Output is correct
21 Correct 63 ms 74488 KB Output is correct
22 Correct 71 ms 74616 KB Output is correct
23 Correct 61 ms 74360 KB Output is correct
24 Correct 70 ms 74616 KB Output is correct
25 Correct 68 ms 74360 KB Output is correct
26 Correct 65 ms 74360 KB Output is correct
27 Correct 64 ms 74360 KB Output is correct
28 Correct 68 ms 74620 KB Output is correct
29 Correct 66 ms 74360 KB Output is correct
30 Correct 60 ms 74360 KB Output is correct
31 Correct 60 ms 74368 KB Output is correct
32 Correct 72 ms 74616 KB Output is correct
33 Correct 69 ms 74616 KB Output is correct
34 Correct 68 ms 74360 KB Output is correct
35 Correct 71 ms 74616 KB Output is correct
36 Correct 69 ms 74668 KB Output is correct
37 Correct 69 ms 74360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 801 ms 166008 KB Output is correct
2 Correct 564 ms 168544 KB Output is correct
3 Correct 736 ms 166768 KB Output is correct
4 Correct 737 ms 166260 KB Output is correct
5 Correct 699 ms 167020 KB Output is correct
6 Correct 675 ms 165788 KB Output is correct
7 Correct 620 ms 167032 KB Output is correct
8 Correct 389 ms 164828 KB Output is correct
9 Correct 384 ms 165624 KB Output is correct
10 Correct 383 ms 167032 KB Output is correct
11 Correct 1130 ms 168560 KB Output is correct
12 Correct 1120 ms 168604 KB Output is correct
13 Correct 1153 ms 170628 KB Output is correct
14 Correct 1158 ms 170740 KB Output is correct
15 Correct 954 ms 168568 KB Output is correct
16 Correct 967 ms 168696 KB Output is correct
17 Correct 949 ms 167772 KB Output is correct
18 Correct 1050 ms 168052 KB Output is correct
19 Correct 44 ms 70776 KB Output is correct
20 Correct 46 ms 70776 KB Output is correct
21 Correct 45 ms 70776 KB Output is correct
22 Correct 48 ms 70776 KB Output is correct
23 Correct 46 ms 70776 KB Output is correct
24 Correct 45 ms 70776 KB Output is correct
25 Correct 45 ms 70776 KB Output is correct
26 Correct 45 ms 70784 KB Output is correct
27 Correct 45 ms 70776 KB Output is correct
28 Correct 45 ms 70784 KB Output is correct
29 Correct 45 ms 70784 KB Output is correct
30 Correct 45 ms 70784 KB Output is correct
31 Correct 45 ms 70776 KB Output is correct
32 Correct 45 ms 70780 KB Output is correct
33 Correct 45 ms 70784 KB Output is correct
34 Correct 45 ms 70776 KB Output is correct
35 Correct 46 ms 70776 KB Output is correct
36 Correct 45 ms 70776 KB Output is correct
37 Correct 45 ms 70776 KB Output is correct
38 Correct 63 ms 74616 KB Output is correct
39 Correct 63 ms 74488 KB Output is correct
40 Correct 71 ms 74616 KB Output is correct
41 Correct 61 ms 74360 KB Output is correct
42 Correct 70 ms 74616 KB Output is correct
43 Correct 68 ms 74360 KB Output is correct
44 Correct 65 ms 74360 KB Output is correct
45 Correct 64 ms 74360 KB Output is correct
46 Correct 68 ms 74620 KB Output is correct
47 Correct 66 ms 74360 KB Output is correct
48 Correct 60 ms 74360 KB Output is correct
49 Correct 60 ms 74368 KB Output is correct
50 Correct 72 ms 74616 KB Output is correct
51 Correct 69 ms 74616 KB Output is correct
52 Correct 68 ms 74360 KB Output is correct
53 Correct 71 ms 74616 KB Output is correct
54 Correct 69 ms 74668 KB Output is correct
55 Correct 69 ms 74360 KB Output is correct
56 Correct 648 ms 168816 KB Output is correct
57 Correct 652 ms 168436 KB Output is correct
58 Correct 617 ms 168696 KB Output is correct
59 Correct 613 ms 169040 KB Output is correct
60 Correct 594 ms 169592 KB Output is correct
61 Correct 607 ms 168608 KB Output is correct
62 Correct 649 ms 168816 KB Output is correct
63 Correct 427 ms 169464 KB Output is correct
64 Correct 427 ms 169592 KB Output is correct
65 Correct 792 ms 168608 KB Output is correct
66 Correct 520 ms 169592 KB Output is correct
67 Correct 1104 ms 170104 KB Output is correct
68 Correct 925 ms 169848 KB Output is correct
69 Correct 794 ms 169896 KB Output is correct
70 Correct 1150 ms 170304 KB Output is correct
71 Correct 949 ms 170108 KB Output is correct
72 Correct 809 ms 169976 KB Output is correct
73 Correct 1125 ms 170364 KB Output is correct
74 Correct 424 ms 169976 KB Output is correct
75 Correct 407 ms 169976 KB Output is correct
76 Correct 1138 ms 171888 KB Output is correct
77 Correct 1204 ms 174760 KB Output is correct
78 Correct 1158 ms 171812 KB Output is correct
79 Correct 1078 ms 170152 KB Output is correct
80 Correct 976 ms 169720 KB Output is correct
81 Correct 438 ms 169848 KB Output is correct
82 Correct 1077 ms 169152 KB Output is correct
83 Correct 1067 ms 169436 KB Output is correct
84 Correct 1048 ms 169452 KB Output is correct
85 Correct 658 ms 170024 KB Output is correct
86 Correct 664 ms 170048 KB Output is correct
87 Correct 702 ms 169976 KB Output is correct
88 Correct 657 ms 169976 KB Output is correct
89 Correct 695 ms 169916 KB Output is correct
90 Correct 1167 ms 172432 KB Output is correct
91 Correct 964 ms 171120 KB Output is correct
92 Correct 724 ms 170104 KB Output is correct
93 Correct 1008 ms 169976 KB Output is correct
94 Correct 870 ms 170236 KB Output is correct
95 Correct 924 ms 169976 KB Output is correct
96 Correct 1199 ms 172524 KB Output is correct
97 Correct 1198 ms 172784 KB Output is correct
98 Correct 1209 ms 173200 KB Output is correct
99 Correct 1205 ms 172908 KB Output is correct
100 Correct 884 ms 172268 KB Output is correct
101 Correct 1197 ms 172776 KB Output is correct
102 Correct 1094 ms 172272 KB Output is correct
103 Correct 765 ms 170364 KB Output is correct