Submission #217747

# Submission time Handle Problem Language Result Execution time Memory
217747 2020-03-30T15:22:29 Z _7_7_ Treatment Project (JOI20_treatment) C++14
100 / 100
712 ms 71012 KB
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef unsigned long long ull;
typedef pair < int, int > pii;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


ll d[N];
vi xx, toDel;
int n, m, x[N];
vpii T[N << 2][2];
set < pair < ll, int > > q;


struct project {
    ll c;
	int t, l, r;
} a[N];

void add (int pos, int lvl, pii x, int v = 1, int tl = 0, int tr = sz(xx) - 1) {
	T[v][lvl].pb(x);
	if (tl == tr)
		return;

	int tm = (tl + tr) >> 1;
	if (pos <= tm)
		add(pos, lvl, x, v << 1, tl, tm);
	else
		add(pos, lvl, x, v << 1 | 1, tm + 1, tr);
}


void f (int l, int r, int lvl, int X, ll Y, int v = 1, int tl = 0, int tr = sz(xx) - 1) {
	if (l > r || l > tr || tl > r)
		return;

	if (l <= tl && tr <= r) {		
		while (sz(T[v][lvl]) && T[v][lvl].back().f <= X) {
		    int i = T[v][lvl].back().s;    
		    if (d[i] == -1) {
		        d[i] = Y + a[i].c;
		        q.insert({d[i], i});
		    }
		    T[v][lvl].ppb();
		}
		return;
	}

	int tm = (tl + tr) >> 1;
	f(l, r, lvl, X, Y, v << 1, tl, tm);
	f(l, r, lvl, X, Y, v << 1 | 1, tm + 1, tr);
}

void Sort (int v = 1, int tl = 0, int tr = sz(xx) - 1) {
    sort(all(T[v][0]));
    sort(all(T[v][1]));

    reverse(all(T[v][0]));
    reverse(all(T[v][1]));
    if (tl == tr)
        return;
        
    int tm = (tl + tr) >> 1;    
    Sort(v << 1, tl, tm);
    Sort(v << 1 | 1, tm + 1, tr);
}
	


main () {
    memset(d, -1, sizeof(d));
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d%d%lld", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
		++a[i].r;
		xx.pb(a[i].t);
	}
	
	sort(all(xx));
	xx.resize(unique(all(xx)) - xx.begin());
	
    for (int i = 1; i <= m; ++i) {
        x[i] = lower_bound(all(xx), a[i].t) - xx.begin();
        if (a[i].l == 1) {
            d[i] = a[i].c;
            q.insert({d[i], i});
        } else {
            add(x[i], 0, {a[i].l + a[i].t, i});
            add(x[i], 1, {a[i].l - a[i].t, i});
        }        
    }
    
    Sort();


	while (sz(q)) {
		int v = q.begin()->s;
		q.erase(q.begin());
		
		f(x[v], m - 1, 0, a[v].r + a[v].t, d[v]);
		f(0, x[v], 1, a[v].r - a[v].t, d[v]);
	}
	
		
	ll mn = INF;	
	for (int i = 1; i <= m; ++i)
		if (a[i].r == n + 1 && d[i] > -1)
			mn = min(mn, d[i]);

	if (mn == INF)
		mn = -1;
	printf("%lld\n", mn);
}




Compilation message

treatment.cpp:101:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
treatment.cpp: In function 'int main()':
treatment.cpp:103:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%lld", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 96 ms 25452 KB Output is correct
2 Correct 98 ms 25580 KB Output is correct
3 Correct 118 ms 26856 KB Output is correct
4 Correct 114 ms 25964 KB Output is correct
5 Correct 140 ms 30572 KB Output is correct
6 Correct 117 ms 25016 KB Output is correct
7 Correct 102 ms 24848 KB Output is correct
8 Correct 86 ms 25580 KB Output is correct
9 Correct 84 ms 25016 KB Output is correct
10 Correct 86 ms 24848 KB Output is correct
11 Correct 171 ms 30988 KB Output is correct
12 Correct 156 ms 30912 KB Output is correct
13 Correct 148 ms 29048 KB Output is correct
14 Correct 149 ms 29068 KB Output is correct
15 Correct 127 ms 24992 KB Output is correct
16 Correct 117 ms 25020 KB Output is correct
17 Correct 110 ms 25036 KB Output is correct
18 Correct 143 ms 30868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19840 KB Output is correct
2 Correct 16 ms 19968 KB Output is correct
3 Correct 15 ms 19968 KB Output is correct
4 Correct 15 ms 19968 KB Output is correct
5 Correct 15 ms 19968 KB Output is correct
6 Correct 16 ms 19840 KB Output is correct
7 Correct 16 ms 19840 KB Output is correct
8 Correct 16 ms 19840 KB Output is correct
9 Correct 17 ms 19888 KB Output is correct
10 Correct 18 ms 19840 KB Output is correct
11 Correct 15 ms 19840 KB Output is correct
12 Correct 17 ms 19956 KB Output is correct
13 Correct 15 ms 19840 KB Output is correct
14 Correct 16 ms 19840 KB Output is correct
15 Correct 16 ms 19840 KB Output is correct
16 Correct 15 ms 19840 KB Output is correct
17 Correct 16 ms 19968 KB Output is correct
18 Correct 16 ms 19968 KB Output is correct
19 Correct 16 ms 19840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19840 KB Output is correct
2 Correct 16 ms 19968 KB Output is correct
3 Correct 15 ms 19968 KB Output is correct
4 Correct 15 ms 19968 KB Output is correct
5 Correct 15 ms 19968 KB Output is correct
6 Correct 16 ms 19840 KB Output is correct
7 Correct 16 ms 19840 KB Output is correct
8 Correct 16 ms 19840 KB Output is correct
9 Correct 17 ms 19888 KB Output is correct
10 Correct 18 ms 19840 KB Output is correct
11 Correct 15 ms 19840 KB Output is correct
12 Correct 17 ms 19956 KB Output is correct
13 Correct 15 ms 19840 KB Output is correct
14 Correct 16 ms 19840 KB Output is correct
15 Correct 16 ms 19840 KB Output is correct
16 Correct 15 ms 19840 KB Output is correct
17 Correct 16 ms 19968 KB Output is correct
18 Correct 16 ms 19968 KB Output is correct
19 Correct 16 ms 19840 KB Output is correct
20 Correct 32 ms 21248 KB Output is correct
21 Correct 30 ms 21376 KB Output is correct
22 Correct 28 ms 21376 KB Output is correct
23 Correct 29 ms 21376 KB Output is correct
24 Correct 33 ms 21884 KB Output is correct
25 Correct 33 ms 21888 KB Output is correct
26 Correct 31 ms 22016 KB Output is correct
27 Correct 30 ms 22016 KB Output is correct
28 Correct 33 ms 21888 KB Output is correct
29 Correct 32 ms 22016 KB Output is correct
30 Correct 28 ms 22016 KB Output is correct
31 Correct 27 ms 22016 KB Output is correct
32 Correct 34 ms 22272 KB Output is correct
33 Correct 34 ms 22272 KB Output is correct
34 Correct 32 ms 21760 KB Output is correct
35 Correct 41 ms 22420 KB Output is correct
36 Correct 33 ms 22264 KB Output is correct
37 Correct 33 ms 21760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 25452 KB Output is correct
2 Correct 98 ms 25580 KB Output is correct
3 Correct 118 ms 26856 KB Output is correct
4 Correct 114 ms 25964 KB Output is correct
5 Correct 140 ms 30572 KB Output is correct
6 Correct 117 ms 25016 KB Output is correct
7 Correct 102 ms 24848 KB Output is correct
8 Correct 86 ms 25580 KB Output is correct
9 Correct 84 ms 25016 KB Output is correct
10 Correct 86 ms 24848 KB Output is correct
11 Correct 171 ms 30988 KB Output is correct
12 Correct 156 ms 30912 KB Output is correct
13 Correct 148 ms 29048 KB Output is correct
14 Correct 149 ms 29068 KB Output is correct
15 Correct 127 ms 24992 KB Output is correct
16 Correct 117 ms 25020 KB Output is correct
17 Correct 110 ms 25036 KB Output is correct
18 Correct 143 ms 30868 KB Output is correct
19 Correct 16 ms 19840 KB Output is correct
20 Correct 16 ms 19968 KB Output is correct
21 Correct 15 ms 19968 KB Output is correct
22 Correct 15 ms 19968 KB Output is correct
23 Correct 15 ms 19968 KB Output is correct
24 Correct 16 ms 19840 KB Output is correct
25 Correct 16 ms 19840 KB Output is correct
26 Correct 16 ms 19840 KB Output is correct
27 Correct 17 ms 19888 KB Output is correct
28 Correct 18 ms 19840 KB Output is correct
29 Correct 15 ms 19840 KB Output is correct
30 Correct 17 ms 19956 KB Output is correct
31 Correct 15 ms 19840 KB Output is correct
32 Correct 16 ms 19840 KB Output is correct
33 Correct 16 ms 19840 KB Output is correct
34 Correct 15 ms 19840 KB Output is correct
35 Correct 16 ms 19968 KB Output is correct
36 Correct 16 ms 19968 KB Output is correct
37 Correct 16 ms 19840 KB Output is correct
38 Correct 32 ms 21248 KB Output is correct
39 Correct 30 ms 21376 KB Output is correct
40 Correct 28 ms 21376 KB Output is correct
41 Correct 29 ms 21376 KB Output is correct
42 Correct 33 ms 21884 KB Output is correct
43 Correct 33 ms 21888 KB Output is correct
44 Correct 31 ms 22016 KB Output is correct
45 Correct 30 ms 22016 KB Output is correct
46 Correct 33 ms 21888 KB Output is correct
47 Correct 32 ms 22016 KB Output is correct
48 Correct 28 ms 22016 KB Output is correct
49 Correct 27 ms 22016 KB Output is correct
50 Correct 34 ms 22272 KB Output is correct
51 Correct 34 ms 22272 KB Output is correct
52 Correct 32 ms 21760 KB Output is correct
53 Correct 41 ms 22420 KB Output is correct
54 Correct 33 ms 22264 KB Output is correct
55 Correct 33 ms 21760 KB Output is correct
56 Correct 485 ms 52456 KB Output is correct
57 Correct 486 ms 53096 KB Output is correct
58 Correct 502 ms 57964 KB Output is correct
59 Correct 504 ms 57832 KB Output is correct
60 Correct 423 ms 52596 KB Output is correct
61 Correct 504 ms 58212 KB Output is correct
62 Correct 512 ms 52584 KB Output is correct
63 Correct 580 ms 64616 KB Output is correct
64 Correct 552 ms 64516 KB Output is correct
65 Correct 124 ms 27112 KB Output is correct
66 Correct 375 ms 52456 KB Output is correct
67 Correct 591 ms 64360 KB Output is correct
68 Correct 465 ms 64232 KB Output is correct
69 Correct 422 ms 63080 KB Output is correct
70 Correct 622 ms 64488 KB Output is correct
71 Correct 491 ms 64100 KB Output is correct
72 Correct 420 ms 64104 KB Output is correct
73 Correct 631 ms 64612 KB Output is correct
74 Correct 343 ms 64104 KB Output is correct
75 Correct 302 ms 64232 KB Output is correct
76 Correct 610 ms 66540 KB Output is correct
77 Correct 686 ms 70852 KB Output is correct
78 Correct 674 ms 64540 KB Output is correct
79 Correct 704 ms 64616 KB Output is correct
80 Correct 647 ms 60392 KB Output is correct
81 Correct 484 ms 64488 KB Output is correct
82 Correct 631 ms 60648 KB Output is correct
83 Correct 687 ms 64872 KB Output is correct
84 Correct 672 ms 64620 KB Output is correct
85 Correct 600 ms 64616 KB Output is correct
86 Correct 593 ms 64616 KB Output is correct
87 Correct 603 ms 64472 KB Output is correct
88 Correct 641 ms 64616 KB Output is correct
89 Correct 613 ms 64648 KB Output is correct
90 Correct 712 ms 70760 KB Output is correct
91 Correct 642 ms 67688 KB Output is correct
92 Correct 600 ms 64616 KB Output is correct
93 Correct 687 ms 64640 KB Output is correct
94 Correct 705 ms 64868 KB Output is correct
95 Correct 670 ms 64616 KB Output is correct
96 Correct 687 ms 70504 KB Output is correct
97 Correct 659 ms 70888 KB Output is correct
98 Correct 675 ms 70776 KB Output is correct
99 Correct 684 ms 70888 KB Output is correct
100 Correct 679 ms 68456 KB Output is correct
101 Correct 671 ms 70632 KB Output is correct
102 Correct 675 ms 71012 KB Output is correct
103 Correct 584 ms 65488 KB Output is correct