Submission #533355

# Submission time Handle Problem Language Result Execution time Memory
533355 2022-03-05T16:29:39 Z idas Sails (IOI07_sails) C++11
0 / 100
134 ms 2520 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;
    }

    cout << l << '\n';

    build(l);

    ll ans=0;
    FOR(i, 1, mx+1)
    {
        ll x=get(i);
        cout << x << " ";
        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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 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 3 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 1592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 2012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 2320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 134 ms 2484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 2520 KB Output isn't correct
2 Halted 0 ms 0 KB -