QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746873 | #9623. 合成大西瓜 | yeah14 | WA | 0ms | 165048kb | C++17 | 5.0kb | 2024-11-14 15:46:51 | 2024-11-14 15:46:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII pair<int ,int>
const int INF = 0x3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int fp(int a, int x, int mod) {
int ans = 1;
while (x) {
if (x & 1)ans *= a;
ans %= mod;
a *= a;
a %= mod;
x >>= 1;
}
return ans;
}
bool check1(int n) {
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0)return 0;
}
return 1;
}
struct tree {
int sum, pre, suf;
int tag = -1;
};
tree tr[4 * N];
int ls(int p) { return p << 1; }
int rs(int p) { return (p << 1) + 1; }
int history[N], tot = 0;
void add_tag(int p, int d, int pl, int pr) {
tr[p].tag += d;
tr[p].sum += d * (pr - pl + 1);
}
void push_down(int p, int len) {
if (tr[p].tag != -1) {
tr[ls(p)].tag = tr[rs(p)].tag = tr[p].tag;
tr[ls(p)].pre = tr[ls(p)].sum = (tr[p].tag == 0) ? 0 : (len - (len >> 1));
tr[rs(p)].pre = tr[rs(p)].sum = (tr[p].tag == 0) ? 0 : (len >> 1);
tr[p].tag = -1;
}
}
void push_up(int p, int len) {
tr[p].pre = tr[ls(p)].pre;
tr[p].suf = tr[rs(p)].suf;
if (tr[ls(p)].pre == (len - (len >> 1))) {
tr[p].pre = tr[ls(p)].pre + tr[rs(p)].pre;
}
if (tr[rs(p)].suf == (len >> 1)) {
tr[p].suf = tr[rs(p)].suf + tr[ls(p)].suf;
}
}
void build(int pl, int pr, int p) {
tr[p].tag = -1;
if (pl == pr) {
tr[p].sum = tr[p].pre = tr[p].suf = 1;
return;
}
int mid = (pl + pr) >> 1;
build(pl, mid, ls(p));
build(mid + 1, pr, rs(p));
push_up(p, pr - pl + 1);
}
void update(int L, int R, int c, int p, int pl, int pr) {
if (L <= pl && R >= pr) {
tr[p].pre = tr[p].suf = tr[p].sum = (c == 0) ? 0 : pr - pl + 1;
tr[p].tag = c;
return;
}
int mid = (pl + pr) >> 1;
if (L <= mid)update(L, R, c, ls(p), pl, mid);
if (R > mid)update(L, R, c, rs(p), mid + 1, pr);
//else update(x, c, rs(p), mid + 1, pr);
push_up(p, pr - pl + 1);
}
int query(int len, int p, int pl, int pr) {
if (pl == pr)return pl;
int mid = (pl + pr) >> 1;
if (len <= tr[ls(p)].sum) {
if (len <= tr[p].pre)return pl;
else return query(len, ls(p), pl, mid);
}
else if (len <= tr[rs(p)].pre + tr[ls(p)].suf) {
return mid - tr[ls(p)].suf + 1;
}
else if (len <= tr[rs(p)].sum) {
if (len <= tr[rs(p)].pre)return pl;
else return query(len, rs(p), mid + 1, pr);
}
}
//const int N = 1e6;
struct edge {
int u, v;
};
struct node {
int w;
int id;
bool operator<(const node a)const {
return w > a.w;
}
};
int degree[N];
node a[N];
//vector<edge>e[N];
priority_queue<node>q;
priority_queue<node>e[N];
node st[N];
int top = 0;
int cnt = 0;
bool vis[N];
void solve() {
int n, m;
cin >> n >> m;
int k = n;
int cnt = n;
for (int i = 1; i <= n; i++) {
cin >> a[i].w;
vis[i] = 1;
a[i].id = i;
q.push(a[i]);
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
/* e[u].push_back({ u,v });
e[v].push_back({ v,u });*/
e[u].push(a[v]);
e[v].push(a[u]);
degree[v]++;
degree[u]++;
}
while (cnt >1) {
while ((vis[q.top().id]==0||degree[q.top().id] < 2)&&!q.empty()) {
q.pop();
if (q.empty())break;
}
if (q.empty())break;
node u = q.top();
q.pop();
node q1 = e[u.id].top();
e[u.id].pop();
while (vis[q1.id] == 0) {
q1 = e[u.id].top();
e[u.id].pop();
}
node q2 = e[u.id].top();
e[u.id].pop();
while (vis[q2.id] == 0) {
q2 = e[u.id].top();
e[u.id].pop();
}
cnt -= 2;
k++;
a[k].w = max(min(q1.w, q2.w), u.w);
a[k].id = k;
map<int, bool>vv;
vis[q1.id] = 0;
vis[q2.id] = 0;
vis[u.id] = 0;
while (!e[q1.id].empty()) {
node p = e[q1.id].top();
e[q1.id].pop();
if (vis[p.id] == 0)continue;
degree[k]++;
e[p.id].push(a[k]);
e[k].push(a[p.id]);
vv[p.id]=1;
}
while (!e[q2.id].empty()) {
node p = e[q2.id].top();
e[q2.id].pop();
if (vis[p.id] == 0)continue;
degree[p.id]--;
if (vv.count(p.id) != 0)continue;
degree[k]++;
e[p.id].push(a[k]);
e[k].push(a[p.id]);
}
q.push(a[k]);
vis[k] = 1;
}
cout << a[k].w << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
/*
7 7
1 1 2 3 1 2 1
1 2
2 3
1 3
2 4
2 5
5 6
5 7
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 165048kb
input:
7 9 1 4 1 3 3 6 7 5 4 3 6 3 4 2 3 5 2 2 6 6 7 5 1 4 6
output:
3
result:
wrong answer 1st lines differ - expected: '6', found: '3'