Submission #529029

# Submission time Handle Problem Language Result Execution time Memory
529029 2022-02-22T02:40:48 Z Evang Growing Trees (BOI11_grow) C++17
100 / 100
118 ms 3768 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)

#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb(x) push_back(x)
#define eb(args...) emplace_back(args)
#define ff first
#define ss second
#define die exit(0)

template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using str = string;

constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------


const int N = 1e5+5;
int n, m, a[N];
ll bit[N];

void upd(int i, int x){
    while(i<=n){
        bit[i] += x;
        i += i&-i;
    }
}

ll at(int i){
    ll ans = 0;
    while(i>0){
        ans += bit[i];
        i -= i&-i;
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout << fixed; clog << fixed; clog << unitbuf;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a+1, a+1+n);
    for(int i = 1; i <= n; ++i)
        upd(i, a[i]-a[i-1]);

    while(m--){
        char t;
        int c, h;
        cin >> t >> c >> h;
        if(t=='F'){
            int i = n+1;
            for(int u = n; u > 0; u /= 2)
                while(i - u > 0 && at(i-u)>=h)
                    i -= u;
            int j = min(n, i+c-1);
            int k = j;
            for(int u = k; u > 0; u /= 2)
                while(k-u>0&&at(k-u)==at(j))
                    k -= u;
            int e = j;
            for(int u = n; u > 0; u /= 2)
                while(e+u<=n&&at(e+u)==at(j))
                    e += u;

            upd(i, 1);
            upd(k, -1);
            upd(e-(j-k+1)+1, 1);
            upd(e+1, -1);
        }else{
            int i = n;
            for(int u = i; u > 0; u /= 2)
                while(i-u>0&&at(i-u)>=c)
                    i -= u;
            int j = 1;
            for(int u = n; u > 0; u /= 2)
                while(j+u<=n&&at(j+u)<=h)
                    j += u;
            if(i==j&&at(i)>h||at(i)<c)
                cout << 0 << el;
            else
                cout << j-i+1 << el;
        }
    }
}

Compilation message

grow.cpp: In function 'int main()':
grow.cpp:133:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  133 |             if(i==j&&at(i)>h||at(i)<c)
      |                ~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 74 ms 2628 KB Output is correct
2 Correct 115 ms 3056 KB Output is correct
3 Correct 51 ms 2984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 3 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 52 ms 1348 KB Output is correct
6 Correct 62 ms 1616 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 28 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1608 KB Output is correct
2 Correct 59 ms 1712 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 34 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1924 KB Output is correct
2 Correct 70 ms 1648 KB Output is correct
3 Correct 7 ms 572 KB Output is correct
4 Correct 64 ms 1700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2228 KB Output is correct
2 Correct 112 ms 2540 KB Output is correct
3 Correct 18 ms 916 KB Output is correct
4 Correct 50 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 2332 KB Output is correct
2 Correct 112 ms 2628 KB Output is correct
3 Correct 61 ms 2784 KB Output is correct
4 Correct 19 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 2428 KB Output is correct
2 Correct 76 ms 2624 KB Output is correct
3 Correct 63 ms 2900 KB Output is correct
4 Correct 18 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 3056 KB Output is correct
2 Correct 118 ms 2484 KB Output is correct
3 Correct 26 ms 2116 KB Output is correct
4 Correct 52 ms 2488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 2812 KB Output is correct
2 Correct 111 ms 3008 KB Output is correct
3 Correct 116 ms 3248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 3768 KB Output is correct