Submission #842673

# Submission time Handle Problem Language Result Execution time Memory
842673 2023-09-03T08:21:52 Z vjudge1 Growing Trees (BOI11_grow) C++17
10 / 100
302 ms 10604 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, a, b) for (int i = (a); i >= (b); --i)
#define pi pair<int,int>
#define ple tuple<int,int,int>
#define fi first
#define se second
#define ii make_pair
#define isz(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define heap_max(a) priority_queue<a>
#define heap_max(a) priority_queue<a,vector<a>,greater<a>>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T>
//using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e6 + 10;

int n, a[N], q;

struct Stree {
       int node[N * 4], lazy[N * 4];
       void fix (int id) {
             node[id] = max(node[id*2], node[id*2+1]);
       }
       void build (int id , int l , int r ) {
            if (l == r) {
                 node[id] = a[l];
                 return;
            }
            int mid = l + r >> 1;
            build(id*2, l, mid);
            build(id*2+1, mid+1, r);
            fix(id);
       }

       void down (int id) {
            if (lazy[id] == 0) return;
            node[id] += lazy[id];
            lazy[id*2] += lazy[id];
            lazy[id*2+1] += lazy[id];
            lazy[id] = 0;
       }

       void update (int id, int l, int r, int u, int v) {
            down(id);
            if (l > v || r < u) return;
            if (l >= u && r <= v) {
                lazy[id]++;
                down(id);
                return;
            }
            int mid = l + r >> 1;
            update(id*2, l, mid, u, v);
            update(id*2+1, mid+1, r, u, v);
            fix(id);
       }

       int get (int id, int l, int r, int u) {
            down(id);
            if (l == r) {return node[id]; }
            int mid = l + r >> 1;
            if (u <= mid) return get(id*2,l,mid,u);
            else return get(id*2+1,mid+1,r,u);
       }
       int get (int u) {
           return get(1,1,n,u);
       }
       void update (int l, int r) {
             update(1, 1, n, l, r);
       }
} st;

int lower (int val) {
    int l = 1, r = n, res = -1;
    while (l <= r) {
           int mid = l + r >> 1;
           if (st.get(mid) >= val) {
               res = mid;
               r = mid - 1;
           } else l = mid + 1;
    }
    return res;
}

int upper (int val) {
     int l = 1, r = n, res = -1;
     while (l <= r) {
           int mid = l + r >> 1;
           if (st.get(mid) <= val) {
              res = mid;
              l = mid + 1;
           } else r = mid - 1;
     }
     return res;
}

int main () {
      file("dynamic");
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

      cin >> n >> q;
      FOR(i,1,n) cin >> a[i];
      FOR(i,0,4*n) st.lazy[i] = 0;
      sort(a+1, a+n+1);
      st.build(1,1,n);
      FOR(d,1,q) {
            char type; cin >> type;
            if (type == 'F') {
                 int c, h; cin >> c >> h;
                 int fr1 = lower(h);
                 if (fr1 == -1) continue;
                 int the_max = st.get(fr1 + c - 1);
                 int lst1 = upper(the_max - 1);
                 int lst2 = upper(the_max);
//                 if(d==3) {
//                     for (int i= 1; i <= n; ++i) cout << st.get(i) << ' ';
//                     cout << endl;
//                 }
                 if (fr1 <= lst1) {
                     st.update(fr1, lst1);
                 }
                 int used = lst1-fr1+1;
                 int fr2 = max(lst1 + 1, lst2 - (c-used) + 1);
                 if (fr2 <= lst2) {
                     st.update(fr2, lst2);
                 }
//                 if (d==3) {
//                     cout << fr1 << ' ' << lst1 << endl;
//                     cout << fr2 << ' ' << lst2 << endl;
//                 }
//                 if(d==3) {
//                     for (int i= 1; i <= n; ++i) cout << st.get(i) << ' ';
//                     cout << endl;
//                     exit(0);
//                 }
            } else {
                 int l, r; cin >> l >> r;
                 int R = upper(r);
                 int L = lower(l);
                 if (min(R,L)==-1) cout << 0 << '\n';
                 else cout << R-L+1 << '\n';
            }
      }
}

Compilation message

grow.cpp:16: warning: "heap_max" redefined
   16 | #define heap_max(a) priority_queue<a,vector<a>,greater<a>>
      | 
grow.cpp:15: note: this is the location of the previous definition
   15 | #define heap_max(a) priority_queue<a>
      | 
grow.cpp: In member function 'void Stree::build(int, int, int)':
grow.cpp:40:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |             int mid = l + r >> 1;
      |                       ~~^~~
grow.cpp: In member function 'void Stree::update(int, int, int, int, int)':
grow.cpp:62:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |             int mid = l + r >> 1;
      |                       ~~^~~
grow.cpp: In member function 'int Stree::get(int, int, int, int)':
grow.cpp:71:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |             int mid = l + r >> 1;
      |                       ~~^~~
grow.cpp: In function 'int lower(int)':
grow.cpp:86:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |            int mid = l + r >> 1;
      |                      ~~^~~
grow.cpp: In function 'int upper(int)':
grow.cpp:98:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   98 |            int mid = l + r >> 1;
      |                      ~~^~~
grow.cpp: In function 'int main()':
grow.cpp:4:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:108:7: note: in expansion of macro 'file'
  108 |       file("dynamic");
      |       ^~~~
grow.cpp:4:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:108:7: note: in expansion of macro 'file'
  108 |       file("dynamic");
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 157 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Incorrect 3 ms 4952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 5644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 5460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 9536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 229 ms 9740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 137 ms 9620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 302 ms 9988 KB Output is correct
2 Incorrect 252 ms 9728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 200 ms 9944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 247 ms 10604 KB Output is correct