답안 #25585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25585 2017-06-23T06:24:16 Z kdh9949 버스 (JOI14_bus) C++14
35 / 100
403 ms 237848 KB
#include <bits/stdc++.h>
using namespace std;

struct E{
	int s, e, st, et;
	bool operator<(const E &oth) const {
		return et > oth.et;
	}
};

struct Qry{
	int t, i;
	bool operator<(const Qry &oth) const {
		return t > oth.t;
	}
};

struct Nod{ int v, l, r; };

Nod nv[19000010];
int cnt;

const int sz = 86400002, inf = 1e9;
struct Seg{
	int rt;
	int mak(){ nv[cnt] = {inf, -1, -1}; return cnt++; }
	void ini(){ rt = mak(); }
	void upd(int x, int v, int c, int p, int q){
		if(p == q){ nv[c].v = min(nv[c].v, v); return; }
		int m = (p + q) / 2;
		if(x <= m){
			if(nv[c].l < 0) nv[c].l = mak();
			upd(x, v, nv[c].l, p, m);
			nv[c].v = min(nv[c].v, nv[nv[c].l].v);
		}
		else{
			if(nv[c].r < 0) nv[c].r = mak();
			upd(x, v, nv[c].r, m + 1, q);
			nv[c].v = min(nv[c].v, nv[nv[c].r].v);
		}
	}
	void upd(int x, int v){ upd(x + 1, v, rt, 1, sz); }
	int get(int s, int e, int c, int p, int q){
		if(e < p || q < s) return inf;
		if(s <= p && q <= e) return nv[c].v;
		int m = (p + q) / 2, ret = inf;
		if(nv[c].l >= 0) ret = min(ret, get(s, e, nv[c].l, p, m));
		if(nv[c].r >= 0) ret = min(ret, get(s, e, nv[c].r, m + 1, q));
		return ret;
	}
	int get(int s, int e){ return get(s + 1, e + 1, rt, 1, sz); }
} S[100010];

int n, m, q, j, t[100010];
vector<E> el;
vector<Qry> ql;

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) S[i].ini();	
	for(int i = 0, s, e, st, et; i < m; i++){
		scanf("%d%d%d%d", &s, &e, &st, &et);
		el.push_back({s, e, st, et});
	}
	sort(el.begin(), el.end());
	scanf("%d", &q);
	for(int i = 0; i < q; i++){
		scanf("%d", t + i);
		S[n].upd(t[i], t[i]);
	}
	for(auto &i : el){
		int nst = S[i.e].get(i.et, sz - 1);
		if(nst < inf){
			if(i.s == 1) S[1].upd(nst, -i.st);
			else S[i.s].upd(i.st, nst);
		}
	}
	for(int i = 0; i < q; i++){
		printf("%d\n", max(-1, -S[1].get(0, t[i])));
	}
}

Compilation message

bus.cpp: In function 'int main()':
bus.cpp:59:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
bus.cpp:62:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &s, &e, &st, &et);
                                      ^
bus.cpp:66:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
                 ^
bus.cpp:68:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", t + i);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 225476 KB Output is correct
2 Correct 0 ms 225476 KB Output is correct
3 Correct 0 ms 225476 KB Output is correct
4 Correct 0 ms 225476 KB Output is correct
5 Correct 0 ms 225476 KB Output is correct
6 Correct 0 ms 225476 KB Output is correct
7 Correct 0 ms 225476 KB Output is correct
8 Correct 0 ms 225476 KB Output is correct
9 Correct 0 ms 225476 KB Output is correct
10 Correct 0 ms 225476 KB Output is correct
11 Correct 3 ms 225616 KB Output is correct
12 Correct 0 ms 225616 KB Output is correct
13 Correct 0 ms 225616 KB Output is correct
14 Correct 0 ms 225616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 225476 KB Output is correct
2 Incorrect 106 ms 225476 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 237848 KB Output is correct
2 Correct 186 ms 237848 KB Output is correct
3 Correct 229 ms 237848 KB Output is correct
4 Correct 266 ms 237848 KB Output is correct
5 Correct 196 ms 237848 KB Output is correct
6 Correct 199 ms 237848 KB Output is correct
7 Correct 236 ms 237848 KB Output is correct
8 Correct 223 ms 237848 KB Output is correct
9 Correct 199 ms 237848 KB Output is correct
10 Correct 299 ms 237848 KB Output is correct
11 Correct 209 ms 237848 KB Output is correct
12 Correct 396 ms 237848 KB Output is correct
13 Correct 339 ms 237848 KB Output is correct
14 Correct 283 ms 237848 KB Output is correct
15 Correct 269 ms 237848 KB Output is correct
16 Correct 123 ms 228632 KB Output is correct
17 Correct 66 ms 228632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 237848 KB Output is correct
2 Correct 343 ms 237848 KB Output is correct
3 Correct 316 ms 237848 KB Output is correct
4 Correct 283 ms 237848 KB Output is correct
5 Correct 349 ms 237848 KB Output is correct
6 Correct 346 ms 237848 KB Output is correct
7 Incorrect 403 ms 237848 KB Output isn't correct
8 Halted 0 ms 0 KB -