답안 #485150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485150 2021-11-06T11:07:11 Z EntropyX Growing Trees (BOI11_grow) C++17
30 / 100
1000 ms 9100 KB
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;

//Bit Functions
#define gcd __gcd
#define lsb __builtin_ffs
#define ldz __builtin_clz
#define tlz __builtin_ctz
#define stc __builtin_popcount
#define prtb(n) cout << bitset<20>(n) << "\n";

//Debugging
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define what_is(x) cerr << #x << " is " << x << endl;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//STL Declarations
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long int>
#define vvl vector<vl>
#define vb vector<bool>
#define pii pair<int,int>
#define fr first
#define sc second
#define u_s unordered_set
#define ump unordered_map
#define ins insert
#define p_q(x) priority_queue<x>

//STL Functions
#define mt make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define muq make_unique
#define all(x) x.begin(),x.end()
#define rot(vec,k) rotate(vec.begin(), vec.begin() + k, vec.end());
#define bs(vec,key) binary_search(all(vec), key)
#define parti(vec,p) partition_point(all(vec), p) - vec.begin()
#define srt(cnt) sort(all(cnt))
#define lb(cnt,x) lower_bound(all(cnt),x)
#define ub(cnt,x) upper_bound(all(cnt),x)
#define mxm(cnt) *max_element(all(cnt))
#define mnm(cnt) *min_element(all(cnt))
#define mxmptr(cnt) max_element(all(cnt))
#define mnmptr(cnt) min_element(all(cnt))
#define rev(cnt) reverse(all(cnt))
#define accum(cnt) accumulate(all(cnt),0)
#define look(cnt) for(auto c:cnt) cout<<c<<" "; cout<<"\n";
#define pre(x,cont) find(all(cont),x)!=cont.end()
#define pb push_back

//Input Functions
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

typedef long long int ll;
ll mod = 10000000007;

//Generalised Sum Function
int sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

vector<int> seive(int N){
    vector<bool> visited(N+1,false);
    vi pr;
    for(int i=2;i<=N;i++){
        if(!visited[i]){
            int j = i;
            pr.pb(j);
            while(j<=N){visited[j] = true;j+=i;}}}
    return pr;
}
ll ceil(ll a,ll b){
    if(b<0)a=-a,b=-b;
    if(a>=0)return (a+b-1)/b;
    return a/b;
}
long long bpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll inverse(ll a,ll m=mod)
{
    return bpow(a,m-2,m);
}
vvl matmul(const vvl &a,const vvl &b,ll M=mod)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    rep(i,0,n)
        rep(j,0,l)
            rep(k,0,m)
            {
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
            }
    return c;
}
vvl matpow(vvl a,ll p,ll M=mod)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    rep(i,0,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}

const ll COMBINATION_SIZE = 300005;
const ll MOD = 1e9+7;

struct Combination {
    long long fac[COMBINATION_SIZE], inv[COMBINATION_SIZE];
    bool built = 0;
    void build(){
        assert(MOD >= COMBINATION_SIZE);
        fac[0] = 1;
        for(int i = 1; i < COMBINATION_SIZE; i++) {
            fac[i] = fac[i - 1] * i % MOD;
        }
        inv[COMBINATION_SIZE - 1] = inverse(fac[COMBINATION_SIZE - 1], MOD);
        for(int i = COMBINATION_SIZE - 2; i >= 0; i--) {
            inv[i] = inv[i + 1] * (i + 1) % MOD;
        }
    }
    long long C(int x, int y){
        if(y < 0 || y > x) {
            return 0;
        }
        if(!built) {
            built = 1;
            build();
        }
        return fac[x] * inv[y] % MOD * inv[x-y] % MOD;
    }
} comb;

void setIO(string s) { // the argument is the filename without the extension
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}

int main(){ _
    int n,q;cin >> n >> q;
    vl segtree(4*n+10,0);
    vector<bool> lazy(4*n+10,false);
    vl val(4*n+10,0);
    auto push = [&](int node,int l,int r){
        if( l == r){
            lazy[node] = false;
        }
        if(lazy[node]){
            int mid = (l+r)/2;
            lazy[node*2] = true;
            lazy[node*2+1] = true;
            val[node*2] += val[node];
            val[node*2+1] += val[node];
            segtree[node*2] += val[node]*1ll*(mid-l+1);
            segtree[node*2+1] += val[node]*1ll*(r-mid);
            lazy[node] = false;
            val[node] = 0;
        }
    };
    function<void(int,int,int,int,int,int)> upd = [&](int node,int L,int R,int l,int r,int v){
        push(node,L,R);
        if(l<=L && R<=r){
            val[node] += v;
            lazy[node] = true;
            segtree[node] += v*1ll*(R-L+1);
        }
        else if(R<l || r<L){
            return;
        }
        else{
            int mid = (L+R)/2;
            upd(node*2,L,mid,l,r,v);
            upd(node*2+1,mid+1,R,l,r,v);
            segtree[node] = segtree[node*2] + segtree[node*2+1];
        }
    };
    function<ll(int,int,int,int,int)> find = [&](int node,int L,int R,int l,int r){
        push(node,L,R);
        if(l<=L && R<=r){
            return segtree[node];
        }
        if(R<l || r<L)
            return 0ll;
        int mid = (L+R)/2;
        return find(node*2,L,mid,l,r) + find(node*2+1,mid+1,R,l,r);
    };
    vi h(n);cin >> h;
    srt(h);
    function<void(int,int,int)> build =  [&](int node,int l,int r){
        if(l == r){
            segtree[node] = h[l];
        }
        else{
            int mid = (l+r)/2;
            build(node*2,l,mid);
            build(node*2+1,mid+1,r);
            segtree[node] = segtree[node*2] + segtree[node*2+1];
        }
    };
    build(1,0,n-1);
    auto findocc = [&](int vv){
        if(find(1,0,n-1,0,0)>=vv)
            return 0;
        int l = 0;
        int r = n;
        while(r-l>1){
            int mid = (l+r)/2;
            if(find(1,0,n-1,mid,mid)>=vv)
                r = mid;
            else
                l = mid;
        }
        return r;
    };
    rep(i,0,q){
        char t;cin >> t;
        if( t == 'F'){
            int c,hh;cin >> c >> hh;
            // Find first tree with height exceeding ot atleast h
            int l1 = findocc(hh);
            if(l1+c-1<n) {
                // There are c trees from this point!
                // End point height!
                int heightr = find(1, 0, n - 1, l1 + c - 1, l1 + c - 1);
                // Last tree with that height!
                int r2 = findocc(heightr + 1) - 1;
                int r1 = findocc(heightr);r1--;
                // Increment [l1,r1] range by 1 and [r2-(c-(r1-l1+1))+1,r2]
                upd(1,0,n-1,l1,r1,1);
                upd(1,0,n-1,r2-(c-(r1-l1+1))+1,r2,1);
            }
            else{
                upd(1,0,n-1,l1,n-1,1);
            }
        }
        else{
            int mini,maxi;cin >> mini >> maxi;
            int start = findocc(mini);
            int end = findocc(maxi+1);
            cout << end-start << "\n";
        }
    }
    return 0;
}

Compilation message

In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from grow.cpp:4:
grow.cpp: In function 'std::vector<std::vector<long long int> > matmul(const std::vector<std::vector<long long int> >&, const std::vector<std::vector<long long int> >&, ll)':
grow.cpp:111:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     assert(m==b.size());
      |            ~^~~~~~~~~~
grow.cpp: In function 'void setIO(std::string)':
grow.cpp:166:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  166 |     freopen((s+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:167:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  167 |     freopen((s+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1026 ms 7580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 460 KB Output is correct
2 Correct 21 ms 484 KB Output is correct
3 Correct 20 ms 460 KB Output is correct
4 Correct 11 ms 460 KB Output is correct
5 Correct 583 ms 1668 KB Output is correct
6 Correct 818 ms 1912 KB Output is correct
7 Correct 44 ms 716 KB Output is correct
8 Correct 166 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 730 ms 2008 KB Output is correct
2 Correct 691 ms 2240 KB Output is correct
3 Correct 12 ms 712 KB Output is correct
4 Correct 327 ms 1808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 595 ms 2376 KB Output is correct
2 Correct 783 ms 2372 KB Output is correct
3 Correct 95 ms 840 KB Output is correct
4 Correct 706 ms 2288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 5928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 6396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 7136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 7768 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 7764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1062 ms 9100 KB Time limit exceeded