Submission #533357

# Submission time Handle Problem Language Result Execution time Memory
533357 2022-03-05T16:33:37 Z idas Sails (IOI07_sails) C++17
5 / 100
128 ms 2028 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>());

    assert(can(n));

    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 '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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 1468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 1592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 1736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 1864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 2028 KB Output isn't correct
2 Halted 0 ms 0 KB -