Submission #962139

# Submission time Handle Problem Language Result Execution time Memory
962139 2024-04-13T07:35:39 Z Yang8on Sails (IOI07_sails) C++14
5 / 100
514 ms 4564 KB
#include <bits/stdc++.h>
#define Y8o "SAILS"
#define maxn 100005
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define f first
#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof()
{
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime()
{
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}


int n;
vector<pii> store;

struct dl
{
    int val, lazy;
} st[4 * maxn];

void down(int id)
{
    int t = st[id].lazy;
    if(!t) return ;

    st[id * 2].val += t, st[id * 2].lazy += t;
    st[id * 2 + 1].val += t, st[id * 2 + 1].lazy += t;

    st[id].lazy = 0;
    return ;
}
void update(int u, int v, int id = 1, int l = 1, int r = maxn - 5)
{
    if(v < l || r < u) return ;
    if(u <= l && r <= v) { st[id].val ++, st[id].lazy ++; return; }

    int mid = (l + r) >> 1;
    down(id);

    update(u, v, id * 2, l, mid);
    update(u, v, id * 2 + 1, mid + 1, r);

    st[id].val = min( st[id * 2].val, st[id * 2 + 1].val );
}
int get(int u, int v, int id = 1, int l = 1, int r = maxn - 5)
{
    if(v < l || r < u) return 1e9;
    if(u <= l && r <= v) return st[id].val;

    down(id);
    int mid = (l + r) >> 1;

    return min( get(u, v, id * 2, l, mid), get(u, v, id * 2 + 1, mid + 1, r) );
}

void solve()
{
    cin >> n;
    for(int i = 1, h, sl; i <= n; i ++) cin >> h >> sl, store.push_back({h, sl});

    sort(store.begin(), store.end(), [](pii x, pii y) { return x.f > y.f; });

    for(pii x : store)
    {
        int h = x.f, sl = x.s;
        int val = get(h, h);

        int l = 1, r = h;
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            if(get(mid, h) != val) l = mid + 1;
            else r = mid - 1;
        }

        if(r == 0) r = h;
        update(max(1, r - sl + 1), r);

        if(r - sl + 1 <= 0)
        {
            int left = sl - r;
            update(h - left + 1, h);
        }
    }

    ll ans = 0;
    for(int i = 1; i <= maxn - 5; i ++)
    {
        int sum = get(i, i);
        ans += 1ll * (sum - 1) * sum / 2;
    }

    cout << ans;
}


int main()
{
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --)
    {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

sails.cpp: In function 'void iof()':
sails.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(Y8o".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 504 KB Output is correct
2 Correct 14 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 134 ms 1764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 2600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 414 ms 4104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 457 ms 4388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 514 ms 4564 KB Output isn't correct
2 Halted 0 ms 0 KB -