Submission #430781

# Submission time Handle Problem Language Result Execution time Memory
430781 2021-06-17T05:02:47 Z deadeye Pilot (NOI19_pilot) C++14
18 / 100
52 ms 10552 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 69
#endif
template <typename Arg>
void __f(string name, Arg arg) {
	cerr << name << " = " << arg << endl;
}
template <typename Head, typename... Tail>
void __f(string names, Head head, Tail... tail) {
	string cur = "";
	for (auto ch: names){if(ch==','){break;}else{cur+=ch;}}
	string nxt = names.substr(cur.size()+2);
	cerr << cur << " = " << head << ", ";
	__f(nxt, tail...);
}

struct DSU {
	vector<int> par, grpsize;
	int groups;
    DSU(int n) {
    	par.resize(n + 1), grpsize.resize(n + 1);
    	groups = n;
        for (int i = 0; i <= n; ++i) {
            par[i] = i;
            grpsize[i] = 1;
        }
    }
    int find(int x) { return (par[x]==x)? x:find(par[x]); }
    bool same(int x, int y) { return find(x) == find(y); }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        groups -= (!same(x, y));
        if (grpsize[x] < grpsize[y]) swap(x, y);
        par[y] = x;
        grpsize[x] += grpsize[y];
    }
    int getsz(int x) {return grpsize[find(x)];}
};
 
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, Q; cin >> N >> Q;
	vector<pi> H(N), Y(Q);
	for (int i = 0; i < N; ++i) {
		cin >> H[i].fi;
		H[i].si = i;
	}
	for (int i = 0; i < Q; ++i) {
		cin >> Y[i].fi;
		Y[i].si = i;
	}
	sort(H.begin(), H.end());
	sort(Y.begin(), Y.end());
	vector<int> can(N), ans(N);
	int idx = 0, sum = 0;
	DSU dsu(N);
	for (int i = 0; i < Q; ++i) {
		int ret = 0;
		while (idx < N && H[idx].fi <= Y[i].fi) {
			int pos = H[idx].si, lx = 0, rx = 0;
			can[pos] = 1;
			if (pos > 0) {
				if (can[pos - 1]) {\
					lx = dsu.getsz(pos - 1);
					dsu.unite(pos - 1, pos);
				}
			}
			if (pos < N - 1) {
				if (can[pos + 1]) {
					rx = dsu.getsz(pos + 1);
					dsu.unite(pos + 1, pos);
				}
			}
			ret += lx + rx + 1 + lx * rx;
			++idx;
		}
		ans[Y[i].si] = ret + sum;
		sum += ret;
	}
	for (int i = 0; i < Q; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 1 ms 220 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 1 ms 220 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 1 ms 220 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5344 KB Output is correct
2 Correct 30 ms 5572 KB Output is correct
3 Correct 28 ms 5152 KB Output is correct
4 Correct 28 ms 5044 KB Output is correct
5 Correct 24 ms 5128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 8204 KB Output is correct
2 Runtime error 51 ms 10552 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8328 KB Output is correct
2 Runtime error 51 ms 10148 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 25 ms 5344 KB Output is correct
12 Correct 30 ms 5572 KB Output is correct
13 Correct 28 ms 5152 KB Output is correct
14 Correct 28 ms 5044 KB Output is correct
15 Correct 24 ms 5128 KB Output is correct
16 Correct 22 ms 5184 KB Output is correct
17 Correct 23 ms 5588 KB Output is correct
18 Correct 22 ms 5572 KB Output is correct
19 Correct 21 ms 5104 KB Output is correct
20 Correct 23 ms 5424 KB Output is correct
21 Correct 27 ms 5096 KB Output is correct
22 Correct 23 ms 5188 KB Output is correct
23 Correct 23 ms 5528 KB Output is correct
24 Correct 24 ms 5192 KB Output is correct
25 Correct 24 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 1 ms 220 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 1 ms 220 KB Output isn't correct