이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 9;
const ll Log2 = 20;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
vector<ll> v;
ll k,n,ans,inc,in[N],out[N];
struct human{
char x,y;
ll L,R;
};
human a[N];
ll Find(ll x){
return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}
void compress(){
sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
//for (ll i = 1;i <= n;i++) a[i].L = Find(a[i].L),a[i].R = Find(a[i].R);
}
ll bit1[N],bit2[N];
void upd(ll p,ll val,ll bit[]){
for (ll i = p;i < N;i += i & -i) bit[i] += val;
}
ll Get(ll p,ll bit[]){
ll res = 0;
for (ll i = p;i > 0;i -= i & -i) res += bit[i];
return res;
}
ll cal_opt(ll opt){
ll inc = 0;
for (ll i = 1;i <= n;i++){
if (a[i].x == a[i].y) continue;
if (a[i].L > opt) inc += 2*(a[i].L - opt);
if (a[i].R < opt) inc += 2*(opt - a[i].R);
}
return inc;
}
void Sub1(){
for (ll i = 1;i <= n;i++){
if (a[i].x != a[i].y) in[Find(a[i].L)]++,out[Find(a[i].R)]++;
}
for (ll i = 1;i < N;i++) upd(i,out[i],bit1),upd(i,in[i],bit2);
ll opt,inc = inf;
for (ll j = 0;j < v.size();j++){
ll i = j + 1; //cout<<Get(2,bit1)<<" "<<out[0]; exit(0);
ll l = Get(i - 1,bit1),r = Get(N - 1,bit2) - Get(i,bit2);
//cout<<v[j]<<" "<<l<<" x "<<r<<"\n";
if (l >= r){
opt = j; break;
}
}
cout<<ans + min(cal_opt(v[opt]),cal_opt(v[opt - 1]));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin>>k>>n;
for (ll i = 1;i <= n;i++){
cin>>a[i].x>>a[i].L>>a[i].y>>a[i].R;
if (a[i].L > a[i].R) swap(a[i].L,a[i].R);
ans += a[i].R - a[i].L;
v.push_back(a[i].L); v.push_back(a[i].R);
if (a[i].x != a[i].y) ans++;
}
compress(); Sub1();
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
bridge.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
bridge.cpp: In function 'void Sub1()':
bridge.cpp:59:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (ll j = 0;j < v.size();j++){
| ~~^~~~~~~~~~
bridge.cpp:58:12: warning: unused variable 'inc' [-Wunused-variable]
58 | ll opt,inc = inf;
| ^~~
bridge.cpp: In function 'int main()':
bridge.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'void Sub1()':
bridge.cpp:67:34: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | cout<<ans + min(cal_opt(v[opt]),cal_opt(v[opt - 1]));
| ^
# | 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... |