답안 #104122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104122 2019-04-04T06:45:09 Z dimash241 새 집 (APIO18_new_home) C++17
45 / 100
3235 ms 169104 KB
# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } 
inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, q, k;
int x[N], t[N], a[N], b[N];
int l[N], y[N];
int ans[N];
vector < int > pp;
map < int, int > M;

int get(int x) {
    auto it = M.lower_bound(x);
    int m = 0;
    if (it != M.end()) m = max(m,it->second-(it->first-x));
    if (it != M.begin()) it--,m = max(m,it->second-(x-it->first));
    return m;
}
void ins(int x,int h) {
    if (get(x) >= h) return ;
    auto it = M.lower_bound(x);
    while (it != M.end()) {
        if (it->second > h-(it->first-x)) break;
        else it = M.erase(it);
    }
    M[x] = h;
    it = M.find(x);
    while (1) {
        if (it == M.begin()) break;
        it--;
        if (it->second > h-(x-it->first)) break;
        else it = M.erase(it);
    }
}

inline void solve () {
	for (int i = 1; i <= n; i ++)
		pp.pb(a[i]), pp.pb(b[i]);
	for (int i = 1; i <= q; i ++) {
		pp.pb(y[i]);
	}
	sort(every(pp));
	pp.resize(unique(every(pp)) - pp.begin());
	vector < vector < pair < int, int > > > add(pp.size() + 2);
	vector < vector < pair < int, int > > > del(pp.size() + 2);
	vector < vector < pair < int, int > > > query(pp.size() + 2);
	multiset < int > bl[k + 1];
	for (int i = 1; i <= k; i ++)
		bl[i].clear();
	for (int i = 1; i <= n; i ++) {
		a[i] = lower_bound(every(pp), a[i]) - pp.begin();
		b[i] = lower_bound(every(pp), b[i]) - pp.begin();
		add[a[i]].pb(mp(x[i], t[i]));
		del[b[i]].pb(mp(x[i], t[i]));
	}

	for (int i = 1; i <= q; i ++) {
		y[i] = lower_bound(every(pp), y[i]) - pp.begin();
		query[y[i]].pb(mp(l[i], i));
	}

	for (int vv = 0; vv < pp.size(); vv ++) {

		for (auto it : add[vv]) bl[it.S].insert(it.F);

		for (auto q : query[vv]) {
			int res = 0;
			for (int w = 1; w <= k; w ++) {
				if (bl[w].empty()) {
					res = -1;
					break;
				}

				int cur = inf;
				auto l = bl[w].upper_bound(q.F);
				if (l != bl[w].end()) {
					cur = min(cur, *l - q.F); 
				}
				if (l != bl[w].begin()) {
					--l;
					cur = min(cur, q.F - *l);
				}
		//		cout << cur << ' ' << w << '\n';
				res = max(res, cur);
			}
			ans[q.S] = res;
		}

		for (auto it : del[vv]) bl[it.S].erase(bl[it.S].find(it.F));
	}
	for (int i = 1; i <= q; ++i) {
		if (ans[i] > 1e8) ans[i] = -1;
		printf("%d\n", ans[i]);
	}
}
vector < pair < int, int > > add[N], del[N], query[N];
multiset < int > bl[N];

int main () {
	scanf("%d%d%d", &n, &k, &q);
    for (int i = 1; i <= n; ++i) {
    	scanf("%d%d%d%d", &x[i], &t[i], &a[i], &b[i]);
    }
    for (int i = 1; i <= q; ++i) {
    	scanf("%d%d", &l[i], &y[i]);
    }
    if (n <= 6e4 && k <= 400) {
    	solve();
    	exit(0);
    }
    
    for (int i = 1; i <= n; ++i)
		pp.pb(a[i]), pp.pb(b[i]);
	for (int i = 1; i <= q; ++i) {
		pp.pb(y[i]);
	}
	sort(every(pp));
	pp.resize(unique(every(pp)) - pp.begin());
	for (int i = 1; i <= n; i ++) {
		a[i] = lower_bound(every(pp), a[i]) - pp.begin();
		b[i] = lower_bound(every(pp), b[i]) - pp.begin();
		add[a[i]].pb(mp(x[i], t[i]));
		del[b[i]].pb(mp(x[i], t[i]));
	}

	for (int i = 1; i <= q; i ++) {
		y[i] = lower_bound(every(pp), y[i]) - pp.begin();
		query[y[i]].pb(mp(l[i], i));
	}
	
	bool f = 0;
	for (auto it : add[0]) bl[it.S].insert(it.F); 
    for (int j = 1; j <= k; ++j) {
                bl[j].insert(-3e8);
                bl[j].insert(3e8);
                for (auto it = ++bl[j].begin(); it != bl[j].end(); it++) {
               		auto it2 = it;
                    it2 --;
                    ins(*it + *it2,*it - *it2);
           		}
    }    
    for (int i = 0; i < pp.size(); ++i) {
    	
      	for (auto it : query[i])
      		ans[it.S] = get(2 * it.F) / 2;
      	for (auto id : del[i]) {
        	int p = id.S;
            auto it = bl[p].find(id.F);
            auto it2 = it;
            it ++, it2 --;
            ins(*it + *it2,*it - *it2);
            bl[p].erase(bl[p].find(id.F));
                
    	}
    }
    for (int i = 1; i <= q; ++i) {
		if (ans[i] > 1e8) ans[i] = -1;
		printf("%d\n", ans[i]);
	}
    return Accepted;
}

// B...a D....

Compilation message

new_home.cpp: In function 'void solve()':
new_home.cpp:100:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int vv = 0; vv < pp.size(); vv ++) {
                   ~~~^~~~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:180:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < pp.size(); ++i) {
                     ~~^~~~~~~~~~~
new_home.cpp:169:7: warning: unused variable 'f' [-Wunused-variable]
  bool f = 0;
       ^
new_home.cpp:138:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &k, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:140:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d%d%d%d", &x[i], &t[i], &a[i], &b[i]);
      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:143:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d%d", &l[i], &y[i]);
      ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 70776 KB Output is correct
2 Correct 68 ms 70848 KB Output is correct
3 Correct 79 ms 70904 KB Output is correct
4 Correct 77 ms 70904 KB Output is correct
5 Correct 82 ms 70904 KB Output is correct
6 Correct 74 ms 71032 KB Output is correct
7 Correct 72 ms 71004 KB Output is correct
8 Correct 72 ms 71032 KB Output is correct
9 Correct 72 ms 71032 KB Output is correct
10 Correct 78 ms 71032 KB Output is correct
11 Correct 76 ms 71068 KB Output is correct
12 Correct 74 ms 71036 KB Output is correct
13 Correct 70 ms 71032 KB Output is correct
14 Correct 77 ms 71044 KB Output is correct
15 Correct 78 ms 71004 KB Output is correct
16 Correct 82 ms 71032 KB Output is correct
17 Correct 74 ms 71032 KB Output is correct
18 Correct 72 ms 71052 KB Output is correct
19 Correct 73 ms 71004 KB Output is correct
20 Correct 74 ms 71032 KB Output is correct
21 Correct 77 ms 70924 KB Output is correct
22 Correct 74 ms 71032 KB Output is correct
23 Correct 73 ms 71032 KB Output is correct
24 Correct 74 ms 71032 KB Output is correct
25 Correct 79 ms 71032 KB Output is correct
26 Correct 72 ms 71132 KB Output is correct
27 Correct 74 ms 70904 KB Output is correct
28 Correct 72 ms 71032 KB Output is correct
29 Correct 72 ms 71032 KB Output is correct
30 Correct 83 ms 70904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 70776 KB Output is correct
2 Correct 68 ms 70848 KB Output is correct
3 Correct 79 ms 70904 KB Output is correct
4 Correct 77 ms 70904 KB Output is correct
5 Correct 82 ms 70904 KB Output is correct
6 Correct 74 ms 71032 KB Output is correct
7 Correct 72 ms 71004 KB Output is correct
8 Correct 72 ms 71032 KB Output is correct
9 Correct 72 ms 71032 KB Output is correct
10 Correct 78 ms 71032 KB Output is correct
11 Correct 76 ms 71068 KB Output is correct
12 Correct 74 ms 71036 KB Output is correct
13 Correct 70 ms 71032 KB Output is correct
14 Correct 77 ms 71044 KB Output is correct
15 Correct 78 ms 71004 KB Output is correct
16 Correct 82 ms 71032 KB Output is correct
17 Correct 74 ms 71032 KB Output is correct
18 Correct 72 ms 71052 KB Output is correct
19 Correct 73 ms 71004 KB Output is correct
20 Correct 74 ms 71032 KB Output is correct
21 Correct 77 ms 70924 KB Output is correct
22 Correct 74 ms 71032 KB Output is correct
23 Correct 73 ms 71032 KB Output is correct
24 Correct 74 ms 71032 KB Output is correct
25 Correct 79 ms 71032 KB Output is correct
26 Correct 72 ms 71132 KB Output is correct
27 Correct 74 ms 70904 KB Output is correct
28 Correct 72 ms 71032 KB Output is correct
29 Correct 72 ms 71032 KB Output is correct
30 Correct 83 ms 70904 KB Output is correct
31 Correct 3230 ms 94888 KB Output is correct
32 Correct 175 ms 76008 KB Output is correct
33 Correct 392 ms 93116 KB Output is correct
34 Correct 2235 ms 93316 KB Output is correct
35 Correct 1478 ms 94908 KB Output is correct
36 Correct 470 ms 94956 KB Output is correct
37 Correct 329 ms 92176 KB Output is correct
38 Correct 283 ms 92332 KB Output is correct
39 Correct 253 ms 91884 KB Output is correct
40 Correct 252 ms 92096 KB Output is correct
41 Correct 425 ms 92136 KB Output is correct
42 Correct 416 ms 91856 KB Output is correct
43 Correct 437 ms 78188 KB Output is correct
44 Correct 411 ms 92264 KB Output is correct
45 Correct 324 ms 92136 KB Output is correct
46 Correct 226 ms 92140 KB Output is correct
47 Correct 255 ms 91240 KB Output is correct
48 Correct 228 ms 91104 KB Output is correct
49 Correct 266 ms 91616 KB Output is correct
50 Correct 337 ms 91752 KB Output is correct
51 Correct 219 ms 91360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 975 ms 119092 KB Output is correct
2 Correct 1612 ms 113768 KB Output is correct
3 Correct 906 ms 141608 KB Output is correct
4 Correct 965 ms 123000 KB Output is correct
5 Correct 2755 ms 126104 KB Output is correct
6 Correct 1938 ms 115224 KB Output is correct
7 Correct 740 ms 141788 KB Output is correct
8 Correct 675 ms 122848 KB Output is correct
9 Correct 674 ms 116388 KB Output is correct
10 Correct 846 ms 112888 KB Output is correct
11 Correct 625 ms 125308 KB Output is correct
12 Correct 616 ms 125688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1516 ms 120620 KB Output is correct
2 Correct 607 ms 104608 KB Output is correct
3 Correct 2049 ms 120956 KB Output is correct
4 Correct 1243 ms 146812 KB Output is correct
5 Correct 1430 ms 124512 KB Output is correct
6 Correct 1283 ms 128320 KB Output is correct
7 Correct 3235 ms 132956 KB Output is correct
8 Correct 2621 ms 122064 KB Output is correct
9 Correct 1184 ms 148060 KB Output is correct
10 Correct 1246 ms 127172 KB Output is correct
11 Correct 1244 ms 121768 KB Output is correct
12 Correct 1467 ms 120032 KB Output is correct
13 Correct 721 ms 131676 KB Output is correct
14 Correct 749 ms 132316 KB Output is correct
15 Correct 904 ms 131804 KB Output is correct
16 Correct 836 ms 132444 KB Output is correct
17 Correct 971 ms 132096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 70776 KB Output is correct
2 Correct 68 ms 70848 KB Output is correct
3 Correct 79 ms 70904 KB Output is correct
4 Correct 77 ms 70904 KB Output is correct
5 Correct 82 ms 70904 KB Output is correct
6 Correct 74 ms 71032 KB Output is correct
7 Correct 72 ms 71004 KB Output is correct
8 Correct 72 ms 71032 KB Output is correct
9 Correct 72 ms 71032 KB Output is correct
10 Correct 78 ms 71032 KB Output is correct
11 Correct 76 ms 71068 KB Output is correct
12 Correct 74 ms 71036 KB Output is correct
13 Correct 70 ms 71032 KB Output is correct
14 Correct 77 ms 71044 KB Output is correct
15 Correct 78 ms 71004 KB Output is correct
16 Correct 82 ms 71032 KB Output is correct
17 Correct 74 ms 71032 KB Output is correct
18 Correct 72 ms 71052 KB Output is correct
19 Correct 73 ms 71004 KB Output is correct
20 Correct 74 ms 71032 KB Output is correct
21 Correct 77 ms 70924 KB Output is correct
22 Correct 74 ms 71032 KB Output is correct
23 Correct 73 ms 71032 KB Output is correct
24 Correct 74 ms 71032 KB Output is correct
25 Correct 79 ms 71032 KB Output is correct
26 Correct 72 ms 71132 KB Output is correct
27 Correct 74 ms 70904 KB Output is correct
28 Correct 72 ms 71032 KB Output is correct
29 Correct 72 ms 71032 KB Output is correct
30 Correct 83 ms 70904 KB Output is correct
31 Correct 3230 ms 94888 KB Output is correct
32 Correct 175 ms 76008 KB Output is correct
33 Correct 392 ms 93116 KB Output is correct
34 Correct 2235 ms 93316 KB Output is correct
35 Correct 1478 ms 94908 KB Output is correct
36 Correct 470 ms 94956 KB Output is correct
37 Correct 329 ms 92176 KB Output is correct
38 Correct 283 ms 92332 KB Output is correct
39 Correct 253 ms 91884 KB Output is correct
40 Correct 252 ms 92096 KB Output is correct
41 Correct 425 ms 92136 KB Output is correct
42 Correct 416 ms 91856 KB Output is correct
43 Correct 437 ms 78188 KB Output is correct
44 Correct 411 ms 92264 KB Output is correct
45 Correct 324 ms 92136 KB Output is correct
46 Correct 226 ms 92140 KB Output is correct
47 Correct 255 ms 91240 KB Output is correct
48 Correct 228 ms 91104 KB Output is correct
49 Correct 266 ms 91616 KB Output is correct
50 Correct 337 ms 91752 KB Output is correct
51 Correct 219 ms 91360 KB Output is correct
52 Runtime error 365 ms 169104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 70776 KB Output is correct
2 Correct 68 ms 70848 KB Output is correct
3 Correct 79 ms 70904 KB Output is correct
4 Correct 77 ms 70904 KB Output is correct
5 Correct 82 ms 70904 KB Output is correct
6 Correct 74 ms 71032 KB Output is correct
7 Correct 72 ms 71004 KB Output is correct
8 Correct 72 ms 71032 KB Output is correct
9 Correct 72 ms 71032 KB Output is correct
10 Correct 78 ms 71032 KB Output is correct
11 Correct 76 ms 71068 KB Output is correct
12 Correct 74 ms 71036 KB Output is correct
13 Correct 70 ms 71032 KB Output is correct
14 Correct 77 ms 71044 KB Output is correct
15 Correct 78 ms 71004 KB Output is correct
16 Correct 82 ms 71032 KB Output is correct
17 Correct 74 ms 71032 KB Output is correct
18 Correct 72 ms 71052 KB Output is correct
19 Correct 73 ms 71004 KB Output is correct
20 Correct 74 ms 71032 KB Output is correct
21 Correct 77 ms 70924 KB Output is correct
22 Correct 74 ms 71032 KB Output is correct
23 Correct 73 ms 71032 KB Output is correct
24 Correct 74 ms 71032 KB Output is correct
25 Correct 79 ms 71032 KB Output is correct
26 Correct 72 ms 71132 KB Output is correct
27 Correct 74 ms 70904 KB Output is correct
28 Correct 72 ms 71032 KB Output is correct
29 Correct 72 ms 71032 KB Output is correct
30 Correct 83 ms 70904 KB Output is correct
31 Correct 3230 ms 94888 KB Output is correct
32 Correct 175 ms 76008 KB Output is correct
33 Correct 392 ms 93116 KB Output is correct
34 Correct 2235 ms 93316 KB Output is correct
35 Correct 1478 ms 94908 KB Output is correct
36 Correct 470 ms 94956 KB Output is correct
37 Correct 329 ms 92176 KB Output is correct
38 Correct 283 ms 92332 KB Output is correct
39 Correct 253 ms 91884 KB Output is correct
40 Correct 252 ms 92096 KB Output is correct
41 Correct 425 ms 92136 KB Output is correct
42 Correct 416 ms 91856 KB Output is correct
43 Correct 437 ms 78188 KB Output is correct
44 Correct 411 ms 92264 KB Output is correct
45 Correct 324 ms 92136 KB Output is correct
46 Correct 226 ms 92140 KB Output is correct
47 Correct 255 ms 91240 KB Output is correct
48 Correct 228 ms 91104 KB Output is correct
49 Correct 266 ms 91616 KB Output is correct
50 Correct 337 ms 91752 KB Output is correct
51 Correct 219 ms 91360 KB Output is correct
52 Correct 975 ms 119092 KB Output is correct
53 Correct 1612 ms 113768 KB Output is correct
54 Correct 906 ms 141608 KB Output is correct
55 Correct 965 ms 123000 KB Output is correct
56 Correct 2755 ms 126104 KB Output is correct
57 Correct 1938 ms 115224 KB Output is correct
58 Correct 740 ms 141788 KB Output is correct
59 Correct 675 ms 122848 KB Output is correct
60 Correct 674 ms 116388 KB Output is correct
61 Correct 846 ms 112888 KB Output is correct
62 Correct 625 ms 125308 KB Output is correct
63 Correct 616 ms 125688 KB Output is correct
64 Correct 1516 ms 120620 KB Output is correct
65 Correct 607 ms 104608 KB Output is correct
66 Correct 2049 ms 120956 KB Output is correct
67 Correct 1243 ms 146812 KB Output is correct
68 Correct 1430 ms 124512 KB Output is correct
69 Correct 1283 ms 128320 KB Output is correct
70 Correct 3235 ms 132956 KB Output is correct
71 Correct 2621 ms 122064 KB Output is correct
72 Correct 1184 ms 148060 KB Output is correct
73 Correct 1246 ms 127172 KB Output is correct
74 Correct 1244 ms 121768 KB Output is correct
75 Correct 1467 ms 120032 KB Output is correct
76 Correct 721 ms 131676 KB Output is correct
77 Correct 749 ms 132316 KB Output is correct
78 Correct 904 ms 131804 KB Output is correct
79 Correct 836 ms 132444 KB Output is correct
80 Correct 971 ms 132096 KB Output is correct
81 Runtime error 365 ms 169104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
82 Halted 0 ms 0 KB -