답안 #247197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
247197 2020-07-11T07:48:15 Z onjo0127 치료 계획 (JOI20_treatment) C++11
100 / 100
1328 ms 428776 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const ll INF = 1LL * 1e18;

inline int getc(vector<int> &V, int x) { return lower_bound(V.begin(), V.end(), x) - V.begin() + 1; }

ll D[100009];
deque<pii> PT[300009], QT[300009];
int T[100009], L[100009], R[100009], C[100009];
priority_queue<pli> pq;
bool chk[100009];

void updP(int idx, int s, int e, int l, int r, int id) {
	if(r < s || e < l) return;
	if(l <= s && e <= r) {
		PT[idx].push_back({T[id], id});
		return;
	}
	int m = s+e >> 1;
	updP(idx*2, s, m, l, r, id);
	updP(idx*2+1, m+1, e, l, r, id);
}

void updQ(int idx, int s, int e, int l, int r, int id) {
	if(r < s || e < l) return;
	if(l <= s && e <= r) {
		QT[idx].push_back({T[id], id});
		return;
	}
	int m = s+e >> 1;
	updQ(idx*2, s, m, l, r, id);
	updQ(idx*2+1, m+1, e, l, r, id);
}

void getP(ll pc, int idx, int s, int e, int p, int t) {
	if(p < s || e < p) return;
	while(PT[idx].size()) {
		int ti, id; tie(ti, id) = PT[idx].back();
		if(ti < t) break;
		PT[idx].pop_back();
		if(chk[id]) continue;
		chk[id] = 1;
		pq.push({-(pc + C[id]), id});
	}
	if(s == e) return;
	int m = s+e >> 1;
	getP(pc, idx*2, s, m, p, t);
	getP(pc, idx*2+1, m+1, e, p, t);
}

void getQ(ll pc, int idx, int s, int e, int p, int t) {
	if(p < s || e < p) return;
	while(QT[idx].size()) {
		int ti, id; tie(ti, id) = QT[idx].front();
		if(ti > t) break;
		QT[idx].pop_front();
		if(chk[id]) continue;
		chk[id] = 1;
		pq.push({-(pc + C[id]), id});
	}
	if(s == e) return;
	int m = s+e >> 1;
	getQ(pc, idx*2, s, m, p, t);
	getQ(pc, idx*2+1, m+1, e, p, t);
}

int main() {
	vector<int> PV, QV;
	int N, M; scanf("%d%d",&N,&M);
	for(int i=1; i<=M; i++) {
		scanf("%d%d%d%d", &T[i], &L[i], &R[i], &C[i]); --L[i];
		if(L[i] == 0) {
			pq.push({-C[i], i});
			chk[i] = 1;
		}
		PV.push_back(R[i] + T[i]);
		QV.push_back(R[i] - T[i]);
	}
	sort(PV.begin(), PV.end()); PV.resize(unique(PV.begin(), PV.end()) - PV.begin());
	sort(QV.begin(), QV.end()); QV.resize(unique(QV.begin(), QV.end()) - QV.begin());
	int PM = PV.size(), QM = QV.size();
	for(int i=1; i<=M; i++) {
		int pl = getc(PV, L[i] + T[i]), pr = getc(PV, R[i] + T[i]);
		updP(1, 1, PM, pl, pr, i);
		int ql = getc(QV, L[i] - T[i]), qr = getc(QV, R[i] - T[i]);
		updQ(1, 1, QM, ql, qr, i);
	}
	for(int i=1; i<=300000; i++) sort(PT[i].begin(), PT[i].end());
	for(int i=1; i<=300000; i++) sort(QT[i].begin(), QT[i].end());
	memset(D, -1, sizeof(D));
	while(pq.size()) {
		ll c; int x; tie(c, x) = pq.top(); pq.pop(); c = -c;
		D[x] = c;
		getP(c, 1, 1, PM, getc(PV, R[x] + T[x]), T[x]);
		getQ(c, 1, 1, QM, getc(QV, R[x] - T[x]), T[x]);
	}
	ll ans = INF;
	for(int i=1; i<=M; i++) if(R[i] == N && D[i] != -1) ans = min(ans, D[i]);
	if(ans != INF) printf("%lld", ans);
	else puts("-1");
	return 0;
}

Compilation message

treatment.cpp: In function 'void updP(int, int, int, int, int, int)':
treatment.cpp:22:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s+e >> 1;
          ~^~
treatment.cpp: In function 'void updQ(int, int, int, int, int, int)':
treatment.cpp:33:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s+e >> 1;
          ~^~
treatment.cpp: In function 'void getP(ll, int, int, int, int, int)':
treatment.cpp:49:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s+e >> 1;
          ~^~
treatment.cpp: In function 'void getQ(ll, int, int, int, int, int)':
treatment.cpp:65:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s+e >> 1;
          ~^~
treatment.cpp: In function 'int main()':
treatment.cpp:72:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, M; scanf("%d%d",&N,&M);
            ~~~~~^~~~~~~~~~~~~~
treatment.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &T[i], &L[i], &R[i], &C[i]); --L[i];
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 407744 KB Output is correct
2 Correct 590 ms 410988 KB Output is correct
3 Correct 788 ms 422092 KB Output is correct
4 Correct 725 ms 422148 KB Output is correct
5 Correct 445 ms 415620 KB Output is correct
6 Correct 456 ms 412396 KB Output is correct
7 Correct 490 ms 410732 KB Output is correct
8 Correct 405 ms 412268 KB Output is correct
9 Correct 424 ms 411628 KB Output is correct
10 Correct 411 ms 410732 KB Output is correct
11 Correct 801 ms 423144 KB Output is correct
12 Correct 831 ms 423168 KB Output is correct
13 Correct 993 ms 415584 KB Output is correct
14 Correct 999 ms 415384 KB Output is correct
15 Correct 819 ms 410856 KB Output is correct
16 Correct 798 ms 410840 KB Output is correct
17 Correct 789 ms 409952 KB Output is correct
18 Correct 786 ms 422556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 404984 KB Output is correct
2 Correct 284 ms 405200 KB Output is correct
3 Correct 287 ms 404984 KB Output is correct
4 Correct 298 ms 404984 KB Output is correct
5 Correct 282 ms 405112 KB Output is correct
6 Correct 285 ms 404984 KB Output is correct
7 Correct 293 ms 404984 KB Output is correct
8 Correct 289 ms 405112 KB Output is correct
9 Correct 281 ms 405112 KB Output is correct
10 Correct 296 ms 405024 KB Output is correct
11 Correct 294 ms 405112 KB Output is correct
12 Correct 279 ms 405112 KB Output is correct
13 Correct 284 ms 404984 KB Output is correct
14 Correct 282 ms 404984 KB Output is correct
15 Correct 295 ms 404984 KB Output is correct
16 Correct 292 ms 404988 KB Output is correct
17 Correct 292 ms 405112 KB Output is correct
18 Correct 289 ms 405112 KB Output is correct
19 Correct 288 ms 404984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 404984 KB Output is correct
2 Correct 284 ms 405200 KB Output is correct
3 Correct 287 ms 404984 KB Output is correct
4 Correct 298 ms 404984 KB Output is correct
5 Correct 282 ms 405112 KB Output is correct
6 Correct 285 ms 404984 KB Output is correct
7 Correct 293 ms 404984 KB Output is correct
8 Correct 289 ms 405112 KB Output is correct
9 Correct 281 ms 405112 KB Output is correct
10 Correct 296 ms 405024 KB Output is correct
11 Correct 294 ms 405112 KB Output is correct
12 Correct 279 ms 405112 KB Output is correct
13 Correct 284 ms 404984 KB Output is correct
14 Correct 282 ms 404984 KB Output is correct
15 Correct 295 ms 404984 KB Output is correct
16 Correct 292 ms 404988 KB Output is correct
17 Correct 292 ms 405112 KB Output is correct
18 Correct 289 ms 405112 KB Output is correct
19 Correct 288 ms 404984 KB Output is correct
20 Correct 325 ms 405496 KB Output is correct
21 Correct 331 ms 405496 KB Output is correct
22 Correct 299 ms 405436 KB Output is correct
23 Correct 304 ms 405200 KB Output is correct
24 Correct 337 ms 405496 KB Output is correct
25 Correct 307 ms 405240 KB Output is correct
26 Correct 305 ms 405240 KB Output is correct
27 Correct 302 ms 405240 KB Output is correct
28 Correct 328 ms 405484 KB Output is correct
29 Correct 306 ms 405240 KB Output is correct
30 Correct 300 ms 405240 KB Output is correct
31 Correct 289 ms 405240 KB Output is correct
32 Correct 331 ms 405752 KB Output is correct
33 Correct 329 ms 405752 KB Output is correct
34 Correct 299 ms 405240 KB Output is correct
35 Correct 326 ms 405748 KB Output is correct
36 Correct 337 ms 405624 KB Output is correct
37 Correct 305 ms 405240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 407744 KB Output is correct
2 Correct 590 ms 410988 KB Output is correct
3 Correct 788 ms 422092 KB Output is correct
4 Correct 725 ms 422148 KB Output is correct
5 Correct 445 ms 415620 KB Output is correct
6 Correct 456 ms 412396 KB Output is correct
7 Correct 490 ms 410732 KB Output is correct
8 Correct 405 ms 412268 KB Output is correct
9 Correct 424 ms 411628 KB Output is correct
10 Correct 411 ms 410732 KB Output is correct
11 Correct 801 ms 423144 KB Output is correct
12 Correct 831 ms 423168 KB Output is correct
13 Correct 993 ms 415584 KB Output is correct
14 Correct 999 ms 415384 KB Output is correct
15 Correct 819 ms 410856 KB Output is correct
16 Correct 798 ms 410840 KB Output is correct
17 Correct 789 ms 409952 KB Output is correct
18 Correct 786 ms 422556 KB Output is correct
19 Correct 285 ms 404984 KB Output is correct
20 Correct 284 ms 405200 KB Output is correct
21 Correct 287 ms 404984 KB Output is correct
22 Correct 298 ms 404984 KB Output is correct
23 Correct 282 ms 405112 KB Output is correct
24 Correct 285 ms 404984 KB Output is correct
25 Correct 293 ms 404984 KB Output is correct
26 Correct 289 ms 405112 KB Output is correct
27 Correct 281 ms 405112 KB Output is correct
28 Correct 296 ms 405024 KB Output is correct
29 Correct 294 ms 405112 KB Output is correct
30 Correct 279 ms 405112 KB Output is correct
31 Correct 284 ms 404984 KB Output is correct
32 Correct 282 ms 404984 KB Output is correct
33 Correct 295 ms 404984 KB Output is correct
34 Correct 292 ms 404988 KB Output is correct
35 Correct 292 ms 405112 KB Output is correct
36 Correct 289 ms 405112 KB Output is correct
37 Correct 288 ms 404984 KB Output is correct
38 Correct 325 ms 405496 KB Output is correct
39 Correct 331 ms 405496 KB Output is correct
40 Correct 299 ms 405436 KB Output is correct
41 Correct 304 ms 405200 KB Output is correct
42 Correct 337 ms 405496 KB Output is correct
43 Correct 307 ms 405240 KB Output is correct
44 Correct 305 ms 405240 KB Output is correct
45 Correct 302 ms 405240 KB Output is correct
46 Correct 328 ms 405484 KB Output is correct
47 Correct 306 ms 405240 KB Output is correct
48 Correct 300 ms 405240 KB Output is correct
49 Correct 289 ms 405240 KB Output is correct
50 Correct 331 ms 405752 KB Output is correct
51 Correct 329 ms 405752 KB Output is correct
52 Correct 299 ms 405240 KB Output is correct
53 Correct 326 ms 405748 KB Output is correct
54 Correct 337 ms 405624 KB Output is correct
55 Correct 305 ms 405240 KB Output is correct
56 Correct 968 ms 422504 KB Output is correct
57 Correct 945 ms 422392 KB Output is correct
58 Correct 874 ms 411512 KB Output is correct
59 Correct 871 ms 411928 KB Output is correct
60 Correct 768 ms 411116 KB Output is correct
61 Correct 876 ms 411500 KB Output is correct
62 Correct 986 ms 422472 KB Output is correct
63 Correct 653 ms 411116 KB Output is correct
64 Correct 656 ms 410860 KB Output is correct
65 Correct 650 ms 410992 KB Output is correct
66 Correct 748 ms 411244 KB Output is correct
67 Correct 1076 ms 414980 KB Output is correct
68 Correct 856 ms 411492 KB Output is correct
69 Correct 671 ms 411580 KB Output is correct
70 Correct 1068 ms 414956 KB Output is correct
71 Correct 879 ms 411620 KB Output is correct
72 Correct 678 ms 411500 KB Output is correct
73 Correct 1126 ms 415060 KB Output is correct
74 Correct 724 ms 411500 KB Output is correct
75 Correct 525 ms 411604 KB Output is correct
76 Correct 1239 ms 427008 KB Output is correct
77 Correct 1328 ms 425408 KB Output is correct
78 Correct 1052 ms 415840 KB Output is correct
79 Correct 1079 ms 413076 KB Output is correct
80 Correct 841 ms 411320 KB Output is correct
81 Correct 798 ms 411884 KB Output is correct
82 Correct 1000 ms 413036 KB Output is correct
83 Correct 962 ms 413332 KB Output is correct
84 Correct 1092 ms 412344 KB Output is correct
85 Correct 695 ms 411756 KB Output is correct
86 Correct 731 ms 411520 KB Output is correct
87 Correct 720 ms 411624 KB Output is correct
88 Correct 746 ms 411628 KB Output is correct
89 Correct 708 ms 411492 KB Output is correct
90 Correct 974 ms 413448 KB Output is correct
91 Correct 1004 ms 412752 KB Output is correct
92 Correct 943 ms 411624 KB Output is correct
93 Correct 1066 ms 412792 KB Output is correct
94 Correct 955 ms 413736 KB Output is correct
95 Correct 950 ms 411756 KB Output is correct
96 Correct 925 ms 413420 KB Output is correct
97 Correct 1183 ms 424624 KB Output is correct
98 Correct 1264 ms 424808 KB Output is correct
99 Correct 1282 ms 424808 KB Output is correct
100 Correct 1223 ms 427560 KB Output is correct
101 Correct 1242 ms 424492 KB Output is correct
102 Correct 1236 ms 428776 KB Output is correct
103 Correct 633 ms 411500 KB Output is correct