Submission #362299

# Submission time Handle Problem Language Result Execution time Memory
362299 2021-02-02T14:49:40 Z ngpin04 Sails (IOI07_sails) C++14
0 / 100
56 ms 2668 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 1e5;

pair <int, int> a[N + 5];

int bit[N + 5];
int n;

void update(int pos, int val)
{
    for (; pos < N; pos += pos & -pos)
        bit[pos]++;
}

void rngupd(int l, int r)
{
    update(l, 1);
    update(r + 1, -1);
}

int getval(int pos)
{
    int res = 0;
    for (; pos > 0; pos -= pos & -pos)
        res += bit[pos];
    return res;
}

int getpos(int x)
{
    int cur = 0;
    int val = 0;
    for (int i = 20; i >= 0; i--) if (cur + (1 << i) <= N)
    {
        if (val + bit[cur + (1 << i)] < x)
        {
            cur += (1 << i);
            val += bit[cur];
        }
    }
    return cur + 1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("file.inp","r",stdin);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].fi >> a[i].se;

    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
        a[i].fi = N - a[i].fi + 1;

    for (int i = 1; i <= n; i++)
    {
        int pos = a[i].fi;
        int cnt = a[i].se;

        int las = getval(pos + cnt - 1);


        int nxt = getpos(las) - 1;
        if (pos <= nxt)
        {
            rngupd(pos, nxt);
            cnt -= (nxt - pos + 1);
        }

        int laspos = getpos(las + 1) - 1;
        rngupd(laspos - cnt + 1, laspos);
    }

    long long ans = 0;
    for (int i = 1; i < N; i++)
    {
        int cnt = getval(i);
        ans += (long long) cnt * (cnt - 1) >> 1;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1036 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1516 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 2028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 2412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -