답안 #533356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533356 2022-03-05T16:29:51 Z idas Sails (IOI07_sails) C++11
5 / 100
128 ms 2016 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()

using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

#define int long long

const int N=1e5+10;
int n, mx, st, fen[N];
vector<pii> inf;

void upd(int p, int x)
{
    for(int i=p; i<N; i+=i&-i){
        fen[i]+=x;
    }
}

void upd_range(int x, int y)
{
    upd(x, 1);
    upd(y+1, -1);
}

int get(int p)
{
    int ret=0;
    for(int i=p; i>0; i-=i&-i){
        ret+=fen[i];
    }
    return ret;
}

void get_start(int hgt, int x)
{
    st=min(st, hgt);
    while(st!=0 && get(st)>=x){
        st--;
    }
}

bool can(int x)
{
    st=mx;
    FOR(i, 0, N) fen[i]=0;
    for(auto[h, k] : inf){
        get_start(h, x);
        if(st<k) return false;
        upd_range(st-k+1, st);
    }
    return true;
}

void build(int l)
{
    st=mx;
    FOR(i, 0, N) fen[i]=0;
    for(auto[h, k] : inf){
        get_start(h, l);
        upd_range(st-k+1, st);
    }
}

signed main()
{
    setIO();
    cin >> n;
    FOR(i, 0, n)
    {
        int h, k;
        cin >> h >> k;
        inf.pb({h,k});
        mx=max(mx, h);
    }

    sort(all(inf), greater<pii>());

    int l=0, r=n;
    while(l<r){
        int m=(l+r)/2;
        if(can(m)) r=m;
        else l=m+1;
    }

    build(l);

    ll ans=0;
    FOR(i, 1, mx+1)
    {
        ll x=get(i);
        ans+=x*(x-1)/2;
    }

    cout << ans;
}

Compilation message

sails.cpp: In function 'bool can(long long int)':
sails.cpp:76:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |     for(auto[h, k] : inf){
      |             ^
sails.cpp: In function 'void build(long long int)':
sails.cpp:88:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |     for(auto[h, k] : inf){
      |             ^
sails.cpp: In function 'void setIO(std::string)':
sails.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Incorrect 1 ms 972 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Incorrect 1 ms 1100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 1632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 1728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 128 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 2016 KB Output isn't correct
2 Halted 0 ms 0 KB -