Submission #114334

# Submission time Handle Problem Language Result Execution time Memory
114334 2019-05-31T23:36:54 Z sebinkim Iqea (innopolis2018_final_C) C++14
51 / 100
2000 ms 187484 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

struct cpnt{
	int p, y, d;
	cpnt() {}
	cpnt(int p, int y, int d) : p(p), y(y), d(d) {}
};

struct minseg{
	int T[303030];
	int sz = 1 << 17;
	
	minseg()
	{
		int i;
		
		for(i=0; i<sz+sz; i++){
			T[i] = 1e9;
		}
	}
	
	void update(int p, int v)
	{
		p += sz;
		T[p] = min(T[p], v);
		
		for(p>>=1; p; p>>=1){
			T[p] = min(T[p << 1], T[p << 1 | 1]);
		}
	}
	
	int get_min(int l, int r)
	{
		int ret = 1e9;
		
		l += sz; r += sz;
		
		for(; l<r; ){
			if(l & 1) ret = min(ret, T[l]);
			if(~r & 1) ret = min(ret, T[r]);
			l = l + 1 >> 1;
			r = r - 1 >> 1;
		}
		
		if(l == r){
			ret = min(ret, T[l]);
		}
		
		return ret;
	}
};

vector <pii> P;
vector <int> V[101010];
vector <cpnt> K[101010];
minseg T1, T2;
int L[101010], R[101010], H[101010];
int S[101010], D[101010];
bool chk[101010];
int n, k;

int dfs1(int p, int r)
{
	S[p] = 1;
	
	for(int &t: V[p]){
		if(t != r && !chk[t]){
			S[p] += dfs1(t, p);
		}
	}
	
	return S[p];
}

void dfs2(int c, int p, int r, vector <cpnt> &X)
{
	vector <cpnt> Y;
	int i, x, y;
	
	for(i=L[p]; i<=R[p]; i++){
		K[H[p] + i - L[p]].push_back(X[i - L[p]]);
	}
	
	for(int &t: V[p]){
		if(t != r && !chk[t]){
			Y.clear();
			for(i=L[t]; i<=R[t]; i++){
				y = min(max(P[H[t] + i - L[t]].second, L[p]), R[p]);
				x = abs(y - P[H[t] + i - L[t]].second) + X[y - L[p]].d + 1;
				Y.emplace_back(c, X[y - L[p]].y, x);
			}
			dfs2(c, t, p, Y);
		}
	}
}

void dnc(int p)
{
	vector <cpnt> X;
	int i, s;
	
	s = dfs1(p, 0);
	
	for(; ; ){
		for(i=0; i<V[p].size(); i++){
			if(S[V[p][i]] < S[p] && S[V[p][i]] * 2 >= s){
				p = V[p][i]; break;
			}
		}
		if(i == V[p].size()) break;
	}
	
	chk[p] = 1;
	
	for(i=L[p]; i<=R[p]; i++){
		X.emplace_back(p, i, 0);
	}
			
	dfs2(p, p, 0, X);
	
	for(int &t: V[p]){
		if(!chk[t]){
			dnc(t);
		}
	}
}

void query1(int p)
{
	int y;
	
	for(cpnt &t: K[p]){
		T1.update(H[t.p] + t.y - L[t.p], t.d - t.y);
		T2.update(H[t.p] + t.y - L[t.p], t.d + t.y);
	}
}

int query2(int p)
{
	int ret;
	
	ret = 1e9;
	
	for(cpnt &t: K[p]){
		ret = min(ret, t.d + T1.get_min(H[t.p], H[t.p] + t.y - L[t.p]) + t.y);
		ret = min(ret, t.d + T2.get_min(H[t.p] + t.y - L[t.p], H[t.p] + R[t.p] - L[t.p]) - t.y);
	}
	
	return ret < 1e8? ret : -1;
}

int main()
{
	vector <int> X, Y;
	int q, i, j, l, x, y, t;
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf("%d%d", &x, &y);
		P.emplace_back(x, y);
	}
	
	sort(P.begin(), P.end());
	
	for(i=0; i<n; ){
		for(j=i; j<n && P[i].first == P[j].first; j=l){
			k ++;
			for(l=j; l<n && P[j].first == P[l].first && P[j].second == P[l].second - l + j; l++){
				D[l] = k;
			}
			L[k] = P[j].second; R[k] = P[l - 1].second; H[k] = j;
			X.push_back(k);
		}
		
		i = j;
		
		for(j=0, l=0; j<X.size() && l<Y.size(); ){
			if(max(L[X[j]], L[Y[l]]) <= min(R[X[j]], R[Y[l]])){
				V[X[j]].push_back(Y[l]);
				V[Y[l]].push_back(X[j]);
			}
			
			if(R[X[j]] < R[Y[l]]) j ++;
			else l ++;
		}
		
		swap(X, Y); X.clear();
	}
	
	dnc(1);
	
	scanf("%d", &q);
	
	for(; q--; ){
		scanf("%d%d%d", &t, &x, &y);
		i = lower_bound(P.begin(), P.end(), pii(x, y)) - P.begin();
		if(t == 1) query1(i);
		else printf("%d\n", query2(i));
	}
	
	return 0;
}

Compilation message

C.cpp: In member function 'int minseg::get_min(int, int)':
C.cpp:45:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    l = l + 1 >> 1;
        ~~^~~
C.cpp:46:10: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
    r = r - 1 >> 1;
        ~~^~~
C.cpp: In function 'void dnc(int)':
C.cpp:109:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0; i<V[p].size(); i++){
            ~^~~~~~~~~~~~
C.cpp:114:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i == V[p].size()) break;
      ~~^~~~~~~~~~~~~~
C.cpp: In function 'void query1(int)':
C.cpp:134:6: warning: unused variable 'y' [-Wunused-variable]
  int y;
      ^
C.cpp: In function 'int main()':
C.cpp:182:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0, l=0; j<X.size() && l<Y.size(); ){
                 ~^~~~~~~~~
C.cpp:182:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0, l=0; j<X.size() && l<Y.size(); ){
                               ~^~~~~~~~~
C.cpp:161:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
C.cpp:164:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~
C.cpp:197:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
C.cpp:200:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &t, &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7168 KB Output is correct
2 Correct 8 ms 7296 KB Output is correct
3 Correct 7 ms 7168 KB Output is correct
4 Correct 19 ms 8320 KB Output is correct
5 Correct 19 ms 8320 KB Output is correct
6 Correct 18 ms 8320 KB Output is correct
7 Correct 25 ms 9112 KB Output is correct
8 Correct 31 ms 9976 KB Output is correct
9 Correct 34 ms 9984 KB Output is correct
10 Correct 24 ms 8952 KB Output is correct
11 Correct 22 ms 8704 KB Output is correct
12 Correct 24 ms 9088 KB Output is correct
13 Correct 22 ms 8960 KB Output is correct
14 Correct 24 ms 9048 KB Output is correct
15 Correct 26 ms 9336 KB Output is correct
16 Correct 29 ms 9464 KB Output is correct
17 Correct 26 ms 9344 KB Output is correct
18 Correct 23 ms 8960 KB Output is correct
19 Correct 40 ms 8824 KB Output is correct
20 Correct 29 ms 9592 KB Output is correct
21 Correct 32 ms 9856 KB Output is correct
22 Correct 32 ms 9592 KB Output is correct
23 Correct 71 ms 14308 KB Output is correct
24 Correct 61 ms 13304 KB Output is correct
25 Correct 31 ms 10616 KB Output is correct
26 Correct 14 ms 7680 KB Output is correct
27 Correct 12 ms 7552 KB Output is correct
28 Correct 57 ms 12948 KB Output is correct
29 Correct 27 ms 9848 KB Output is correct
30 Correct 21 ms 8832 KB Output is correct
31 Correct 20 ms 8832 KB Output is correct
32 Correct 24 ms 9216 KB Output is correct
33 Correct 47 ms 12512 KB Output is correct
34 Correct 19 ms 8704 KB Output is correct
35 Correct 19 ms 8576 KB Output is correct
36 Correct 20 ms 8960 KB Output is correct
37 Correct 40 ms 12280 KB Output is correct
38 Correct 31 ms 9464 KB Output is correct
39 Correct 42 ms 8668 KB Output is correct
40 Correct 20 ms 8448 KB Output is correct
41 Correct 59 ms 14712 KB Output is correct
42 Correct 70 ms 15480 KB Output is correct
43 Correct 25 ms 9600 KB Output is correct
44 Correct 51 ms 13084 KB Output is correct
45 Correct 55 ms 14224 KB Output is correct
46 Correct 12 ms 7552 KB Output is correct
47 Correct 26 ms 9216 KB Output is correct
48 Correct 22 ms 8832 KB Output is correct
49 Correct 21 ms 8704 KB Output is correct
50 Correct 19 ms 8320 KB Output is correct
51 Correct 18 ms 8192 KB Output is correct
52 Correct 19 ms 8192 KB Output is correct
53 Correct 41 ms 12384 KB Output is correct
54 Correct 46 ms 11896 KB Output is correct
55 Correct 28 ms 10232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7168 KB Output is correct
2 Correct 8 ms 7296 KB Output is correct
3 Correct 7 ms 7168 KB Output is correct
4 Correct 19 ms 8320 KB Output is correct
5 Correct 19 ms 8320 KB Output is correct
6 Correct 18 ms 8320 KB Output is correct
7 Correct 25 ms 9112 KB Output is correct
8 Correct 31 ms 9976 KB Output is correct
9 Correct 34 ms 9984 KB Output is correct
10 Correct 24 ms 8952 KB Output is correct
11 Correct 22 ms 8704 KB Output is correct
12 Correct 24 ms 9088 KB Output is correct
13 Correct 22 ms 8960 KB Output is correct
14 Correct 24 ms 9048 KB Output is correct
15 Correct 26 ms 9336 KB Output is correct
16 Correct 29 ms 9464 KB Output is correct
17 Correct 26 ms 9344 KB Output is correct
18 Correct 23 ms 8960 KB Output is correct
19 Correct 40 ms 8824 KB Output is correct
20 Correct 29 ms 9592 KB Output is correct
21 Correct 32 ms 9856 KB Output is correct
22 Correct 32 ms 9592 KB Output is correct
23 Correct 71 ms 14308 KB Output is correct
24 Correct 61 ms 13304 KB Output is correct
25 Correct 31 ms 10616 KB Output is correct
26 Correct 14 ms 7680 KB Output is correct
27 Correct 12 ms 7552 KB Output is correct
28 Correct 57 ms 12948 KB Output is correct
29 Correct 27 ms 9848 KB Output is correct
30 Correct 21 ms 8832 KB Output is correct
31 Correct 20 ms 8832 KB Output is correct
32 Correct 24 ms 9216 KB Output is correct
33 Correct 47 ms 12512 KB Output is correct
34 Correct 19 ms 8704 KB Output is correct
35 Correct 19 ms 8576 KB Output is correct
36 Correct 20 ms 8960 KB Output is correct
37 Correct 40 ms 12280 KB Output is correct
38 Correct 31 ms 9464 KB Output is correct
39 Correct 42 ms 8668 KB Output is correct
40 Correct 20 ms 8448 KB Output is correct
41 Correct 59 ms 14712 KB Output is correct
42 Correct 70 ms 15480 KB Output is correct
43 Correct 25 ms 9600 KB Output is correct
44 Correct 51 ms 13084 KB Output is correct
45 Correct 55 ms 14224 KB Output is correct
46 Correct 12 ms 7552 KB Output is correct
47 Correct 26 ms 9216 KB Output is correct
48 Correct 22 ms 8832 KB Output is correct
49 Correct 21 ms 8704 KB Output is correct
50 Correct 19 ms 8320 KB Output is correct
51 Correct 18 ms 8192 KB Output is correct
52 Correct 19 ms 8192 KB Output is correct
53 Correct 41 ms 12384 KB Output is correct
54 Correct 46 ms 11896 KB Output is correct
55 Correct 28 ms 10232 KB Output is correct
56 Correct 143 ms 9180 KB Output is correct
57 Correct 129 ms 9720 KB Output is correct
58 Correct 100 ms 9124 KB Output is correct
59 Correct 96 ms 10616 KB Output is correct
60 Correct 100 ms 10284 KB Output is correct
61 Correct 117 ms 11768 KB Output is correct
62 Correct 111 ms 10680 KB Output is correct
63 Correct 96 ms 10360 KB Output is correct
64 Correct 111 ms 10360 KB Output is correct
65 Correct 96 ms 10416 KB Output is correct
66 Correct 93 ms 10104 KB Output is correct
67 Correct 108 ms 11000 KB Output is correct
68 Correct 138 ms 11484 KB Output is correct
69 Correct 105 ms 10624 KB Output is correct
70 Correct 97 ms 10488 KB Output is correct
71 Correct 100 ms 10616 KB Output is correct
72 Correct 106 ms 11000 KB Output is correct
73 Correct 94 ms 10040 KB Output is correct
74 Correct 100 ms 11640 KB Output is correct
75 Correct 73 ms 8924 KB Output is correct
76 Correct 69 ms 9336 KB Output is correct
77 Correct 187 ms 14840 KB Output is correct
78 Correct 112 ms 11512 KB Output is correct
79 Correct 81 ms 10844 KB Output is correct
80 Correct 169 ms 14496 KB Output is correct
81 Correct 101 ms 10968 KB Output is correct
82 Correct 206 ms 16828 KB Output is correct
83 Correct 205 ms 16952 KB Output is correct
84 Correct 99 ms 11512 KB Output is correct
85 Correct 190 ms 15400 KB Output is correct
86 Correct 207 ms 15652 KB Output is correct
87 Correct 68 ms 8696 KB Output is correct
88 Correct 117 ms 10620 KB Output is correct
89 Correct 100 ms 10360 KB Output is correct
90 Correct 93 ms 10012 KB Output is correct
91 Correct 93 ms 9592 KB Output is correct
92 Correct 97 ms 9212 KB Output is correct
93 Correct 99 ms 9368 KB Output is correct
94 Correct 323 ms 14044 KB Output is correct
95 Correct 148 ms 13308 KB Output is correct
96 Correct 120 ms 12024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 15572 KB Output is correct
2 Correct 381 ms 49636 KB Output is correct
3 Correct 359 ms 35436 KB Output is correct
4 Correct 383 ms 35556 KB Output is correct
5 Correct 394 ms 40044 KB Output is correct
6 Correct 409 ms 39772 KB Output is correct
7 Correct 275 ms 30288 KB Output is correct
8 Correct 147 ms 18792 KB Output is correct
9 Correct 123 ms 14052 KB Output is correct
10 Correct 330 ms 30248 KB Output is correct
11 Correct 179 ms 18744 KB Output is correct
12 Correct 145 ms 14120 KB Output is correct
13 Correct 119 ms 13652 KB Output is correct
14 Correct 128 ms 13544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2047 ms 187484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7168 KB Output is correct
2 Correct 8 ms 7296 KB Output is correct
3 Correct 7 ms 7168 KB Output is correct
4 Correct 19 ms 8320 KB Output is correct
5 Correct 19 ms 8320 KB Output is correct
6 Correct 18 ms 8320 KB Output is correct
7 Correct 25 ms 9112 KB Output is correct
8 Correct 31 ms 9976 KB Output is correct
9 Correct 34 ms 9984 KB Output is correct
10 Correct 24 ms 8952 KB Output is correct
11 Correct 22 ms 8704 KB Output is correct
12 Correct 24 ms 9088 KB Output is correct
13 Correct 22 ms 8960 KB Output is correct
14 Correct 24 ms 9048 KB Output is correct
15 Correct 26 ms 9336 KB Output is correct
16 Correct 29 ms 9464 KB Output is correct
17 Correct 26 ms 9344 KB Output is correct
18 Correct 23 ms 8960 KB Output is correct
19 Correct 40 ms 8824 KB Output is correct
20 Correct 29 ms 9592 KB Output is correct
21 Correct 32 ms 9856 KB Output is correct
22 Correct 32 ms 9592 KB Output is correct
23 Correct 71 ms 14308 KB Output is correct
24 Correct 61 ms 13304 KB Output is correct
25 Correct 31 ms 10616 KB Output is correct
26 Correct 14 ms 7680 KB Output is correct
27 Correct 12 ms 7552 KB Output is correct
28 Correct 57 ms 12948 KB Output is correct
29 Correct 27 ms 9848 KB Output is correct
30 Correct 21 ms 8832 KB Output is correct
31 Correct 20 ms 8832 KB Output is correct
32 Correct 24 ms 9216 KB Output is correct
33 Correct 47 ms 12512 KB Output is correct
34 Correct 19 ms 8704 KB Output is correct
35 Correct 19 ms 8576 KB Output is correct
36 Correct 20 ms 8960 KB Output is correct
37 Correct 40 ms 12280 KB Output is correct
38 Correct 31 ms 9464 KB Output is correct
39 Correct 42 ms 8668 KB Output is correct
40 Correct 20 ms 8448 KB Output is correct
41 Correct 59 ms 14712 KB Output is correct
42 Correct 70 ms 15480 KB Output is correct
43 Correct 25 ms 9600 KB Output is correct
44 Correct 51 ms 13084 KB Output is correct
45 Correct 55 ms 14224 KB Output is correct
46 Correct 12 ms 7552 KB Output is correct
47 Correct 26 ms 9216 KB Output is correct
48 Correct 22 ms 8832 KB Output is correct
49 Correct 21 ms 8704 KB Output is correct
50 Correct 19 ms 8320 KB Output is correct
51 Correct 18 ms 8192 KB Output is correct
52 Correct 19 ms 8192 KB Output is correct
53 Correct 41 ms 12384 KB Output is correct
54 Correct 46 ms 11896 KB Output is correct
55 Correct 28 ms 10232 KB Output is correct
56 Correct 143 ms 9180 KB Output is correct
57 Correct 129 ms 9720 KB Output is correct
58 Correct 100 ms 9124 KB Output is correct
59 Correct 96 ms 10616 KB Output is correct
60 Correct 100 ms 10284 KB Output is correct
61 Correct 117 ms 11768 KB Output is correct
62 Correct 111 ms 10680 KB Output is correct
63 Correct 96 ms 10360 KB Output is correct
64 Correct 111 ms 10360 KB Output is correct
65 Correct 96 ms 10416 KB Output is correct
66 Correct 93 ms 10104 KB Output is correct
67 Correct 108 ms 11000 KB Output is correct
68 Correct 138 ms 11484 KB Output is correct
69 Correct 105 ms 10624 KB Output is correct
70 Correct 97 ms 10488 KB Output is correct
71 Correct 100 ms 10616 KB Output is correct
72 Correct 106 ms 11000 KB Output is correct
73 Correct 94 ms 10040 KB Output is correct
74 Correct 100 ms 11640 KB Output is correct
75 Correct 73 ms 8924 KB Output is correct
76 Correct 69 ms 9336 KB Output is correct
77 Correct 187 ms 14840 KB Output is correct
78 Correct 112 ms 11512 KB Output is correct
79 Correct 81 ms 10844 KB Output is correct
80 Correct 169 ms 14496 KB Output is correct
81 Correct 101 ms 10968 KB Output is correct
82 Correct 206 ms 16828 KB Output is correct
83 Correct 205 ms 16952 KB Output is correct
84 Correct 99 ms 11512 KB Output is correct
85 Correct 190 ms 15400 KB Output is correct
86 Correct 207 ms 15652 KB Output is correct
87 Correct 68 ms 8696 KB Output is correct
88 Correct 117 ms 10620 KB Output is correct
89 Correct 100 ms 10360 KB Output is correct
90 Correct 93 ms 10012 KB Output is correct
91 Correct 93 ms 9592 KB Output is correct
92 Correct 97 ms 9212 KB Output is correct
93 Correct 99 ms 9368 KB Output is correct
94 Correct 323 ms 14044 KB Output is correct
95 Correct 148 ms 13308 KB Output is correct
96 Correct 120 ms 12024 KB Output is correct
97 Correct 135 ms 15572 KB Output is correct
98 Correct 381 ms 49636 KB Output is correct
99 Correct 359 ms 35436 KB Output is correct
100 Correct 383 ms 35556 KB Output is correct
101 Correct 394 ms 40044 KB Output is correct
102 Correct 409 ms 39772 KB Output is correct
103 Correct 275 ms 30288 KB Output is correct
104 Correct 147 ms 18792 KB Output is correct
105 Correct 123 ms 14052 KB Output is correct
106 Correct 330 ms 30248 KB Output is correct
107 Correct 179 ms 18744 KB Output is correct
108 Correct 145 ms 14120 KB Output is correct
109 Correct 119 ms 13652 KB Output is correct
110 Correct 128 ms 13544 KB Output is correct
111 Execution timed out 2047 ms 187484 KB Time limit exceeded
112 Halted 0 ms 0 KB -