답안 #216792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216792 2020-03-28T04:30:59 Z abacaba 치료 계획 (JOI20_treatment) C++14
4 / 100
259 ms 524292 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}
 
const int mod = 1e9 + 7;
const ll inf = 2e18;
const int N = 1e5 + 15;
int n, m;
ll ans = -1;
 
vector <int> compress;
int sz;
 
ll d[N];
 
priority_queue <pair <ll, int>, vector <pair <ll, int>>, greater <pair <ll, int>>> q;
 
inline int gt(int x) {
	return lower_bound(compress.begin(), compress.end(), x) - compress.begin() + 1;
}
 
struct pt {
	int t, l, r, c;
} a[N];
 
struct segment_tree {
	vector <pii> t[N << 2];
	void build(int v, int tl, int tr) {
		if(tl == tr) {
			if(!t[v].empty()) {
				sort(t[v].begin(), t[v].end(), [&](pii x, pii y) {
					return x > y;
				});
			}
			return;
		}
		int mid = tl + tr >> 1;
		build(v << 1, tl, tr);
		build(v << 1 | 1, mid + 1, tr);
		merge(t[v << 1].begin(), t[v << 1].end(), t[v << 1 | 1].begin(), t[v << 1 | 1].end(), back_inserter(t[v]));
		reverse(t[v].begin(), t[v].end());
	}
	void get(int v, int tl, int tr, int l, int r, int val, ll nw) {
		if(tl > r || tr < l)
			return;
		if(tl >= l && tr <= r) {
			while(!t[v].empty() && t[v].back().f <= val) {
				int i = t[v].back().se;
				if(d[i] > nw + a[i].c)
					q.push(mp(d[i] = nw + a[i].c, i));
				t[v].ppb();
			}
			return;
		}
		int mid = tl + tr >> 1;
		get(v << 1, tl, mid, l, r, val, nw);
		get(v << 1 | 1, mid + 1, tr, l, r, val, nw);
	}
	inline void update(int v, int tl, int tr, int pos, pii val) {
		while(1) {
 
			if(tl == tr) {
				t[v].pb(val);
				return;
			}
 
			int mid = tl + tr >> 1;
			if(pos <= mid)
				v <<= 1, tr = mid;
			else
				v = v << 1 | 1, tl = mid + 1;
		}
	}
} t1, t2;
 
inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}
 
main() {
	fill(d, d + N, inf);
	n = nxt(); m = nxt();
	for(int i = 1; i <= m; ++i) {
		a[i].t = nxt(); a[i].l = nxt(); a[i].r = nxt(); a[i].c = nxt();
		compress.pb(a[i].t);
	}
	sort(compress.begin(), compress.end());
	compress.erase(unique(compress.begin(), compress.end()), compress.end());
 
	sz = compress.size();
 
	for(int i = 1; i <= m; ++i) {
		--a[i].l;
		if(a[i].l == 0) {
			d[i] = a[i].c;
			q.push({d[i], i});
		}
		else {
			t1.update(1, 1, sz, gt(a[i].t), mp(a[i].l + a[i].t, i));
			t2.update(1, 1, sz, gt(a[i].t), mp(a[i].l - a[i].t, i));
		}
	}
	t1.build(1, 1, sz);
	t2.build(1, 1, sz);
	while(!q.empty()) {
		int dist = q.top().f, i = q.top().se;
		q.pop();
		if(dist > d[i])
			continue;
 
		t1.get(1, 1, sz, gt(a[i].t), sz, a[i].r + a[i].t, d[i]);
		t2.get(1, 1, sz, 1, gt(a[i].t), a[i].r - a[i].t, d[i]);
	}
	for(int i = 1; i <= m; ++i) {
		if(a[i].r != n || d[i] == inf)
			continue;
		if(ans == -1 || d[i] < ans)
			ans = d[i];
	}
	cout << ans << endl;
	return 0;
}

Compilation message

treatment.cpp: In member function 'void segment_tree::build(int, int, int)':
treatment.cpp:85:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
treatment.cpp: In member function 'void segment_tree::get(int, int, int, int, int, int, long long int)':
treatment.cpp:103:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
treatment.cpp: In member function 'void segment_tree::update(int, int, int, int, std::pair<int, int>)':
treatment.cpp:115:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int mid = tl + tr >> 1;
              ~~~^~~~
treatment.cpp: At global scope:
treatment.cpp:130:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
treatment.cpp: In function 'int nxt()':
treatment.cpp:126:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &x);
  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 24300 KB Output is correct
2 Correct 104 ms 24300 KB Output is correct
3 Correct 109 ms 24292 KB Output is correct
4 Correct 108 ms 23920 KB Output is correct
5 Correct 120 ms 25612 KB Output is correct
6 Correct 112 ms 24232 KB Output is correct
7 Correct 105 ms 24296 KB Output is correct
8 Correct 106 ms 24428 KB Output is correct
9 Correct 96 ms 24300 KB Output is correct
10 Correct 93 ms 24332 KB Output is correct
11 Correct 131 ms 25580 KB Output is correct
12 Correct 134 ms 25840 KB Output is correct
13 Correct 127 ms 25620 KB Output is correct
14 Correct 132 ms 25676 KB Output is correct
15 Correct 121 ms 23708 KB Output is correct
16 Correct 129 ms 24300 KB Output is correct
17 Correct 116 ms 24300 KB Output is correct
18 Correct 127 ms 25580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19840 KB Output is correct
2 Runtime error 259 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19840 KB Output is correct
2 Runtime error 259 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 24300 KB Output is correct
2 Correct 104 ms 24300 KB Output is correct
3 Correct 109 ms 24292 KB Output is correct
4 Correct 108 ms 23920 KB Output is correct
5 Correct 120 ms 25612 KB Output is correct
6 Correct 112 ms 24232 KB Output is correct
7 Correct 105 ms 24296 KB Output is correct
8 Correct 106 ms 24428 KB Output is correct
9 Correct 96 ms 24300 KB Output is correct
10 Correct 93 ms 24332 KB Output is correct
11 Correct 131 ms 25580 KB Output is correct
12 Correct 134 ms 25840 KB Output is correct
13 Correct 127 ms 25620 KB Output is correct
14 Correct 132 ms 25676 KB Output is correct
15 Correct 121 ms 23708 KB Output is correct
16 Correct 129 ms 24300 KB Output is correct
17 Correct 116 ms 24300 KB Output is correct
18 Correct 127 ms 25580 KB Output is correct
19 Correct 17 ms 19840 KB Output is correct
20 Runtime error 259 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Halted 0 ms 0 KB -