Submission #839133

# Submission time Handle Problem Language Result Execution time Memory
839133 2023-08-28T19:25:35 Z hariaakas646 Sails (IOI07_sails) C++17
0 / 100
45 ms 16724 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

template <class T>
struct BIT
{
    int size;
    vector<T> bit;
    vector<T> vec;

    BIT(int n) : size(n), bit(n + 1), vec(n + 1) {}

    int lsb(int x)
    {
        return x & (-x);
    }

    void set(int id, T v)
    {
        add(id, v - vec[id]);
    }

    void add(int id, T v)
    {
        if (id == 0)
            return;
        vec[id] += v;
        while (id <= size)
        {
            bit[id] += v;
            id += lsb(id);
        }
    }

    T query(int id)
    {
        T tot = 0;
        if (id == 0)
            return tot;
        while (id >= 1)
        {
            tot += bit[id];
            id -= lsb(id);
        }
        return tot;
    }
};

int main()
{
    int n;
    scd(n);

    vii vec(n);

    frange(i, n)
    {
        scd(vec[i].f);
        scd(vec[i].s);
    }

    sort(all(vec));

    int h = 1e6;

    BIT<lli> bit(h + 10);

    int id = 0;

    frange(i, n)
    {
        pii p = vec[i];
        id %= p.f;
        id++;
        bit.add(id, 1);
        id += p.s - 1;
        if (id > p.f)
        {
            bit.add(p.f + 1, -1);
            bit.add(1, 1);
            p.s = (id - p.f);
            id = 1;
            id += p.s - 1;
        }
        bit.add(id + 1, -1);
    }
    lli tot = 0;
    forr(i, 1, h + 1)
    {
        lli v = bit.query(i);
        // printf("%lld\n", v);
        tot += v * (v - 1) / 2;
    }
    printf("%lld", tot);
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
sails.cpp:75:5: note: in expansion of macro 'scd'
   75 |     scd(n);
      |     ^~~
sails.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
sails.cpp:81:9: note: in expansion of macro 'scd'
   81 |         scd(vec[i].f);
      |         ^~~
sails.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
sails.cpp:82:9: note: in expansion of macro 'scd'
   82 |         scd(vec[i].s);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 16024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 16084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 16340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 16556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 16596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 16724 KB Output isn't correct
2 Halted 0 ms 0 KB -