QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#62192 | #2832. Graph Theory | xuancx# | WA | 83ms | 5624kb | C++20 | 2.5kb | 2022-11-17 16:55:54 | 2022-11-17 16:56:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define maxn 200010
#define PII pair<int,int>
#define PIII pair<int ,PII>
int tree[maxn << 2];
void pushdown(int root){
if(tree[root]){
tree[root * 2] = tree[root * 2 + 1] = tree[root];
tree[root] = 0;
}
}
void build(int l,int r,int root){
if(l==r){
tree[root] = 0;
return;
}
int mid = l + (r - l) / 2;
build(l, mid, root * 2);
build(mid + 1, r, root * 2 + 1);
}
void update(int fl,int fr,int l,int r,int k,int root){
if(fl<=l&&r<=fr){
tree[root] = k;
return;
}
pushdown(root);
int mid = l + (r - l) / 2;
if(fl<=mid)
update(fl, fr, l, mid, k, root * 2);
if(fr>mid)
update(fl, fr, mid + 1, r, k, root * 2 + 1);
}
int res[maxn];
int top = 0;
void query(int l,int r,int root){
if(l==r){
res[++top] = tree[root];
//cout << top << " " << root << " " << tree[root] << endl;
return;
}
int mid = l + (r - l) / 2;
pushdown(root);
query(l, mid, root * 2);
query(mid + 1, r, root * 2 + 1);
}
int main(void){
int n, m;
while(scanf("%d%d",&n,&m)!=EOF){
top = 0;
build(1, n, 1);
vector<PIII>v;
int mn = 0;
for (int i = 1;i<=m;i++){
int a, b;
scanf("%d%d", &a, &b);
int len;
if(a>b){
swap(a, b);
}
mn = max(mn,min(b - a, n - (b - a)));
len = max(b - a, n - (b - a));
if(a==b)continue;
v.push_back({len, {a, b}});
}
sort(v.begin(), v.end());
for(auto x:v){
//cout << x.first << endl;
//x.first==big
int a, b;
a = x.second.first;
b = x.second.second;
if(x.first!=b-a){
update(a, b-1, 1, n, x.first, 1);
//cout << "!" << a << " " << b << " " << x.first << endl;
}
else {
//cout << "?" << a << " " << b << " " << x.first << endl;
if(a>1)
update(1, a - 1, 1, n, x.first, 1);
update(b, n, 1, n, x.first, 1);
}
}
query(1, n, 1);
int mnn = 1e9;
for (int i = 1;i<=n;i++){
//cout << res[i] << endl;
mnn = min(mnn, res[i]);
}
if(mnn==0){
cout << mn << endl;
}
else
cout << mnn << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3440kb
input:
3 2 1 2 2 3 3 2 1 1 2 2 3 3 1 2 2 3 3 1
output:
1 0 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 83ms
memory: 5624kb
input:
17 17 6 10 1 9 14 6 12 13 5 4 15 17 14 15 6 5 10 6 10 11 2 9 9 6 17 15 9 15 4 8 1 4 13 15 13 19 11 10 12 10 10 5 2 8 12 11 8 3 1 7 10 9 8 5 1 5 9 4 8 7 12 10 6 8 13 1 5 8 11 5 10 8 7 7 16 14 9 5 8 1 4 16 10 8 16 15 15 1 13 5 9 3 4 4 9 7 7 2 5 4 5 11 9 14 5 13 1 5 4 5 4 1 4 4 1 1 5 3 3 5 4 1 3 2 5 1 ...
output:
8 6 8 2 1 2 3 6 2 6 2 9 10 10 8 10 3 4 7 7 9 10 4 7 6 8 2 2 2 3 6 5 8 4 2 3 4 1 2 6 9 2 6 4 1 2 1 3 4 8 8 6 3 5 7 6 3 8 1 2 3 2 1 1 8 5 7 5 7 7 9 9 3 2 3 7 4 5 6 6 5 1 1 2 4 1 1 7 3 5 4 6 7 5 7 6 1 2 8 5 6 4 5 3 3 7 7 6 8 2 3 3 3 7 12 7 1 2 2 2 6 7 11 7 2 3 1 3 3 2 1 11 9 5 8 5 2 3 1 5 6 3 6 6 1 8 3...
result:
wrong answer 7th lines differ - expected: '7', found: '3'