Submission #216733

# Submission time Handle Problem Language Result Execution time Memory
216733 2020-03-27T23:51:14 Z ainta Treatment Project (JOI20_treatment) C++17
100 / 100
1107 ms 106336 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define pii pair<int,int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define N_ 101000
#define SZ 131072

using namespace std;
struct AA {
	int t, l, r, c;	
}P[N_];
long long D[N_], INF = 1e18;
int L, n;
struct Tree {
	int X[N_], Y[N_], Loc[N_][20];
	int n, PV[SZ+SZ], ReNum[N_];
	pli IT[SZ + SZ], MM[SZ+SZ];
	vector<pii>TP;
	vector<int>YY[SZ + SZ], Num[SZ+SZ], chk[SZ + SZ];
	set<pil>Set[SZ + SZ];
	
	struct point {
		int y, num;
	}w[N_];
	void Add(AA t, int num) {
		n++;
		X[n] = t.l + t.t;
		Y[n] = t.l - t.t;
		TP.push_back({ X[n],n });
	}
	void Calc2(int nd) {
		while (PV[nd] < chk[nd].size() && chk[nd][PV[nd]])PV[nd]++;
		if (PV[nd] == chk[nd].size()) {
			MM[nd] = { INF,0 };
			return;
		}
		auto it = Set[nd].lower_bound({ PV[nd],0ll });
		if (it == Set[nd].end()) {
			MM[nd] = { INF,0 };
			return;
		}
		MM[nd] = { it->second, Num[nd][PV[nd]] };
	}
	void UDT(int nd, int b, int e) {
		IT[nd] = MM[nd];
		if (b == e)return;
		IT[nd] = min(IT[nd], min(IT[nd * 2], IT[nd * 2 + 1]));
	}
	void Build(int nd, int b, int e, int dep) {
		int i;
		vector<pii>V;
		for (i = b; i <= e; i++) V.push_back({ w[i].y,w[i].num });
		sort(V.begin(), V.end());
		int sz = V.size();
		YY[nd].resize(sz);
		chk[nd].resize(sz);
		Num[nd].resize(sz);
		PV[nd] = 0;
		for (i = 0; i < sz; i++)chk[nd][i] = 0;
		for (i = 0; i < sz; i++) {
			YY[nd][i] = V[i].first;
			Num[nd][i] = V[i].second;
			Loc[V[i].second][dep] = i;
		}
		MM[nd] = IT[nd] = { INF,0 };
		if (b == e)return;
		int m = (b + e) >> 1;
		Build(nd * 2, b, m, dep + 1);
		Build(nd * 2 + 1, m + 1, e, dep + 1);
		UDT(nd, b, e);
	}
	void init() {
		sort(X + 1, X + n + 1);
		sort(TP.begin(), TP.end());
		int cc = 0;
		for (auto &t : TP) {
			int x = t.second;
			w[++cc] = { Y[x],x };
			ReNum[x] = cc;
		}
		Build(1, 1, n, 0);
	}
	void Del2(int nd, int b, int e, int x, int dep) {
		if (Loc[x][dep] >= chk[nd].size()) {
			while (1) {}
		}
		chk[nd][Loc[x][dep]] = 1;
		Calc2(nd);
		if (b != e) {
			int m = (b + e) >> 1;
			if (ReNum[x] <= m)Del2(nd * 2, b, m, x, dep + 1);
			else Del2(nd * 2 + 1, m + 1, e, x, dep + 1);
		}
		UDT(nd, b, e);
	}
	void Del(int a) {
		Del2(1, 1, n, a, 0);
	}
	void Put2(int nd, int y, long long g) {
		int pv = lower_bound(YY[nd].begin(), YY[nd].end(), y + 1) - YY[nd].begin();
		if (!pv)return;
		pv--;
		auto it = Set[nd].lower_bound({ pv,-1ll });
		if (it != Set[nd].end() && it->second <= g)return;
		if (it != Set[nd].end() && it->first == pv)Set[nd].erase(it);
		Set[nd].insert({ pv,g });
		it = Set[nd].find({ pv,g });
		while (it!=Set[nd].begin()) {
			auto it2 = it; it2--;
			if (it2->second >= g)Set[nd].erase(it2);
			else break;
		}
	}
	void Put(int nd, int b, int e, int s, int l, int y, long long g, int dep) {
		if (s > l)return;
		if (s <= b && e <= l) {
			Put2(nd, y, g);
			Calc2(nd);
			UDT(nd, b, e);
			return;
		}
		int m = (b + e) >> 1;
		if (s <= m)Put(nd * 2, b, m, s, l, y, g, dep + 1);
		if (l > m)Put(nd * 2 + 1, m + 1, e, s, l, y, g, dep + 1);
		UDT(nd, b, e);
	}
	void Ins(int x, int y, long long g) {
		int pv = lower_bound(X + 1, X + n + 1, x + 1) - X;
		pv--;
		Put(1, 1, n, 1, pv, y, g, 0);
	}
}T;
void Insert(int a) {
	T.Ins(P[a].r+1 + P[a].t, P[a].r+1 - P[a].t, D[a]);
	T.Del(a);
}
int main() {
	//freopen("input.txt", "r", stdin);
	int i, j;
	scanf("%d%d", &L, &n);
	T.n = 0;
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d%d", &P[i].t, &P[i].l, &P[i].r, &P[i].c);
		T.Add(P[i], i);
		D[i] = INF;
	}
	T.init();
	for (i = 1; i <= n; i++) {
		if (P[i].l == 1) {
			D[i] = P[i].c;
			Insert(i);
		}
	}
	while (1) {
		pli tp = T.IT[1];
		if (tp.first > 1e17)break;
		D[tp.second] = tp.first + P[tp.second].c;
		Insert(tp.second);
	}
	long long res = INF;
	for (i = 1; i <= n; i++) {
		if (P[i].r == L)res = min(res, D[i]);
	}
	if (res > 1e17)res = -1;
	printf("%lld\n", res);
}

Compilation message

treatment.cpp: In member function 'void Tree::Calc2(int)':
treatment.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (PV[nd] < chk[nd].size() && chk[nd][PV[nd]])PV[nd]++;
          ~~~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:36:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (PV[nd] == chk[nd].size()) {
       ~~~~~~~^~~~~~~~~~~~~~~~~
treatment.cpp: In member function 'void Tree::Del2(int, int, int, int, int)':
treatment.cpp:87:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (Loc[x][dep] >= chk[nd].size()) {
       ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
treatment.cpp: In function 'int main()':
treatment.cpp:142:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
treatment.cpp:143:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &L, &n);
  ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:146:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &P[i].t, &P[i].l, &P[i].r, &P[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 480 ms 94144 KB Output is correct
2 Correct 391 ms 90500 KB Output is correct
3 Correct 492 ms 90968 KB Output is correct
4 Correct 479 ms 91128 KB Output is correct
5 Correct 405 ms 89448 KB Output is correct
6 Correct 418 ms 89448 KB Output is correct
7 Correct 414 ms 89448 KB Output is correct
8 Correct 313 ms 89444 KB Output is correct
9 Correct 306 ms 89452 KB Output is correct
10 Correct 314 ms 89476 KB Output is correct
11 Correct 527 ms 90708 KB Output is correct
12 Correct 538 ms 90704 KB Output is correct
13 Correct 502 ms 91872 KB Output is correct
14 Correct 487 ms 91856 KB Output is correct
15 Correct 504 ms 91960 KB Output is correct
16 Correct 486 ms 91868 KB Output is correct
17 Correct 483 ms 91840 KB Output is correct
18 Correct 524 ms 90712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 39296 KB Output is correct
2 Correct 25 ms 39472 KB Output is correct
3 Correct 28 ms 39296 KB Output is correct
4 Correct 32 ms 39400 KB Output is correct
5 Correct 25 ms 39296 KB Output is correct
6 Correct 23 ms 39296 KB Output is correct
7 Correct 24 ms 39296 KB Output is correct
8 Correct 24 ms 39296 KB Output is correct
9 Correct 24 ms 39296 KB Output is correct
10 Correct 33 ms 39424 KB Output is correct
11 Correct 32 ms 39296 KB Output is correct
12 Correct 25 ms 39424 KB Output is correct
13 Correct 25 ms 39296 KB Output is correct
14 Correct 32 ms 39296 KB Output is correct
15 Correct 27 ms 39424 KB Output is correct
16 Correct 23 ms 39296 KB Output is correct
17 Correct 27 ms 39472 KB Output is correct
18 Correct 27 ms 39296 KB Output is correct
19 Correct 25 ms 39424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 39296 KB Output is correct
2 Correct 25 ms 39472 KB Output is correct
3 Correct 28 ms 39296 KB Output is correct
4 Correct 32 ms 39400 KB Output is correct
5 Correct 25 ms 39296 KB Output is correct
6 Correct 23 ms 39296 KB Output is correct
7 Correct 24 ms 39296 KB Output is correct
8 Correct 24 ms 39296 KB Output is correct
9 Correct 24 ms 39296 KB Output is correct
10 Correct 33 ms 39424 KB Output is correct
11 Correct 32 ms 39296 KB Output is correct
12 Correct 25 ms 39424 KB Output is correct
13 Correct 25 ms 39296 KB Output is correct
14 Correct 32 ms 39296 KB Output is correct
15 Correct 27 ms 39424 KB Output is correct
16 Correct 23 ms 39296 KB Output is correct
17 Correct 27 ms 39472 KB Output is correct
18 Correct 27 ms 39296 KB Output is correct
19 Correct 25 ms 39424 KB Output is correct
20 Correct 41 ms 41728 KB Output is correct
21 Correct 41 ms 41720 KB Output is correct
22 Correct 43 ms 42216 KB Output is correct
23 Correct 59 ms 41976 KB Output is correct
24 Correct 52 ms 41848 KB Output is correct
25 Correct 58 ms 42232 KB Output is correct
26 Correct 54 ms 42232 KB Output is correct
27 Correct 41 ms 41984 KB Output is correct
28 Correct 46 ms 41848 KB Output is correct
29 Correct 47 ms 41976 KB Output is correct
30 Correct 39 ms 41600 KB Output is correct
31 Correct 48 ms 41592 KB Output is correct
32 Correct 56 ms 41720 KB Output is correct
33 Correct 44 ms 41592 KB Output is correct
34 Correct 45 ms 41720 KB Output is correct
35 Correct 47 ms 41728 KB Output is correct
36 Correct 49 ms 41632 KB Output is correct
37 Correct 42 ms 41708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 94144 KB Output is correct
2 Correct 391 ms 90500 KB Output is correct
3 Correct 492 ms 90968 KB Output is correct
4 Correct 479 ms 91128 KB Output is correct
5 Correct 405 ms 89448 KB Output is correct
6 Correct 418 ms 89448 KB Output is correct
7 Correct 414 ms 89448 KB Output is correct
8 Correct 313 ms 89444 KB Output is correct
9 Correct 306 ms 89452 KB Output is correct
10 Correct 314 ms 89476 KB Output is correct
11 Correct 527 ms 90708 KB Output is correct
12 Correct 538 ms 90704 KB Output is correct
13 Correct 502 ms 91872 KB Output is correct
14 Correct 487 ms 91856 KB Output is correct
15 Correct 504 ms 91960 KB Output is correct
16 Correct 486 ms 91868 KB Output is correct
17 Correct 483 ms 91840 KB Output is correct
18 Correct 524 ms 90712 KB Output is correct
19 Correct 26 ms 39296 KB Output is correct
20 Correct 25 ms 39472 KB Output is correct
21 Correct 28 ms 39296 KB Output is correct
22 Correct 32 ms 39400 KB Output is correct
23 Correct 25 ms 39296 KB Output is correct
24 Correct 23 ms 39296 KB Output is correct
25 Correct 24 ms 39296 KB Output is correct
26 Correct 24 ms 39296 KB Output is correct
27 Correct 24 ms 39296 KB Output is correct
28 Correct 33 ms 39424 KB Output is correct
29 Correct 32 ms 39296 KB Output is correct
30 Correct 25 ms 39424 KB Output is correct
31 Correct 25 ms 39296 KB Output is correct
32 Correct 32 ms 39296 KB Output is correct
33 Correct 27 ms 39424 KB Output is correct
34 Correct 23 ms 39296 KB Output is correct
35 Correct 27 ms 39472 KB Output is correct
36 Correct 27 ms 39296 KB Output is correct
37 Correct 25 ms 39424 KB Output is correct
38 Correct 41 ms 41728 KB Output is correct
39 Correct 41 ms 41720 KB Output is correct
40 Correct 43 ms 42216 KB Output is correct
41 Correct 59 ms 41976 KB Output is correct
42 Correct 52 ms 41848 KB Output is correct
43 Correct 58 ms 42232 KB Output is correct
44 Correct 54 ms 42232 KB Output is correct
45 Correct 41 ms 41984 KB Output is correct
46 Correct 46 ms 41848 KB Output is correct
47 Correct 47 ms 41976 KB Output is correct
48 Correct 39 ms 41600 KB Output is correct
49 Correct 48 ms 41592 KB Output is correct
50 Correct 56 ms 41720 KB Output is correct
51 Correct 44 ms 41592 KB Output is correct
52 Correct 45 ms 41720 KB Output is correct
53 Correct 47 ms 41728 KB Output is correct
54 Correct 49 ms 41632 KB Output is correct
55 Correct 42 ms 41708 KB Output is correct
56 Correct 604 ms 92536 KB Output is correct
57 Correct 525 ms 93116 KB Output is correct
58 Correct 518 ms 97148 KB Output is correct
59 Correct 526 ms 97236 KB Output is correct
60 Correct 680 ms 100792 KB Output is correct
61 Correct 517 ms 97112 KB Output is correct
62 Correct 620 ms 92492 KB Output is correct
63 Correct 446 ms 94048 KB Output is correct
64 Correct 502 ms 98132 KB Output is correct
65 Correct 481 ms 94044 KB Output is correct
66 Correct 569 ms 97372 KB Output is correct
67 Correct 987 ms 101156 KB Output is correct
68 Correct 1099 ms 106336 KB Output is correct
69 Correct 755 ms 102104 KB Output is correct
70 Correct 966 ms 100272 KB Output is correct
71 Correct 1107 ms 104472 KB Output is correct
72 Correct 689 ms 99544 KB Output is correct
73 Correct 994 ms 99644 KB Output is correct
74 Correct 400 ms 89424 KB Output is correct
75 Correct 363 ms 89428 KB Output is correct
76 Correct 608 ms 90744 KB Output is correct
77 Correct 879 ms 91904 KB Output is correct
78 Correct 545 ms 92128 KB Output is correct
79 Correct 1022 ms 101004 KB Output is correct
80 Correct 532 ms 92332 KB Output is correct
81 Correct 377 ms 89420 KB Output is correct
82 Correct 552 ms 91912 KB Output is correct
83 Correct 623 ms 92724 KB Output is correct
84 Correct 1078 ms 100796 KB Output is correct
85 Correct 552 ms 92380 KB Output is correct
86 Correct 776 ms 101608 KB Output is correct
87 Correct 599 ms 94664 KB Output is correct
88 Correct 553 ms 93624 KB Output is correct
89 Correct 727 ms 98872 KB Output is correct
90 Correct 800 ms 93648 KB Output is correct
91 Correct 747 ms 93476 KB Output is correct
92 Correct 818 ms 98320 KB Output is correct
93 Correct 995 ms 100808 KB Output is correct
94 Correct 599 ms 90576 KB Output is correct
95 Correct 846 ms 99288 KB Output is correct
96 Correct 854 ms 93400 KB Output is correct
97 Correct 798 ms 92484 KB Output is correct
98 Correct 883 ms 92632 KB Output is correct
99 Correct 802 ms 92528 KB Output is correct
100 Correct 648 ms 89812 KB Output is correct
101 Correct 812 ms 92328 KB Output is correct
102 Correct 733 ms 90460 KB Output is correct
103 Correct 606 ms 91892 KB Output is correct