제출 #411935

#제출 시각아이디문제언어결과실행 시간메모리
411935cpp219Palembang Bridges (APIO15_bridge)C++14
0 / 100
10 ms3544 KiB
#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;
}

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;
    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 = v[j]; break;
        }
    }
    //cout<<opt; exit(0);
    for (ll i = 1;i <= n;i++){
        if (a[i].x == a[i].y) continue;
        if (a[i].L > opt) ans += 2*(a[i].L - opt);
        if (a[i].R < opt) ans += 2*(opt - a[i].R);
    }
    cout<<ans;
}

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:49: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]
   49 |     for (ll j = 0;j < v.size();j++){
      |                   ~~^~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'void Sub1()':
bridge.cpp:61:41: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |         if (a[i].R < opt) ans += 2*(opt - a[i].R);
      |                                    ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...