| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1301227 | Thanhs | Pilot (NOI19_pilot) | C++20 | 353 ms | 54732 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 1e6 + 5;
int n, q, a[NM], ans[NM], b[NM], p[NM], sum;
int f(int x)
{
x = -x;
return x * (x + 1) / 2;
}
int find(int u) {return p[u] < 0 ? u : p[u] = find(p[u]);}
void join(int u, int v)
{
u = find(u), v = find(v);
if (u == v || !b[u] || !b[v])
return;
sum -= f(p[u]) + f(p[v]);
if (p[u] > p[v])
swap(u, v);
p[u] += p[v];
p[v] = u;
sum += f(p[u]);
}
void solve()
{
vector<pair<int, int>> v;
memset(p, -1, sizeof p);
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
v.push_back({a[i], i});
}
sort(all(v));
int cr = 0;
for (int i = 1; i <= 1e6; i++)
{
// cout << ' ' << i << endl;
while (cr < v.size() && v[cr].fi == i)
{
int x = v[cr].se;
// cout << x << endl;
b[x] = 1;
sum++;
if (x > 1)
join(x, x - 1);
if (x < n)
join(x, x + 1);
cr++;
}
ans[i] = sum;
}
while (q--)
{
int x;
cin >> x;
cout << ans[x] << endl;
}
}
signed main()
{
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
else if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
