제출 #1072486

#제출 시각아이디문제언어결과실행 시간메모리
1072486vjudge1송신탑 (IOI22_towers)C++17
23 / 100
4059 ms5240 KiB
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2")
// #pragma GCC target("popcnt")
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
 
#define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
 
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)

bool cmin(int &a, int b){if(b<a){a=b;return 1;}return 0;}
bool cmax(int &a, int b){if(b>a){a=b;return 1;}return 0;}
void valid(ll in){cout<<((in)?"YES\n":"NO\n");}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
ll gauss(ll n){return (n*(n+1))/2;}
struct SegTree{
    vi st;
    int n;
    SegTree(int n): n(n), st(4*n+4, 0) {}
    void update(int i,int x) {update(1,0,n-1,i,x);}
    void update(int nodo,int l,int r,int i,int x) {
        if(l == r) st[nodo] = x;
        else {
            int m = (l+r)/2;
            if(i <= m) update(nodo*2, l, m, i, x);
            else update(nodo*2+1, m+1, r, i, x);
            st[nodo] = max(st[nodo*2], st[nodo*2+1]);
        }
    }
    int query(int l,int r) {return query(1, 0, n-1, l, r);} 
    int query(int nodo,int l,int r,int i,int j){
        if(l>j || r<i) return INT_MIN;
        if(l>=i && r<=j) return st[nodo]; 
        int m =(l+r)/2;
        return max(query(nodo*2, l, m, i, j), query(nodo*2+1, m+1, r, i, j));
    }
};
int n;
vi h;
void init(int nn, vi hh){
    n = nn;
    h = hh;
}
/*
11
5 31 49 51 20 60 40 50 30 52 1
1
0 10 10
7
10 20 60 40 50 30 70
3
1 5 10
2 2 100
0 6 17
*/
int max_towers(int l,int r,int d){
    vi ord;
    fore(i, l, r+1)ord.pb(h[i]);
    sort(all(ord));
    auto pos = [&](int a){
        return upper_bound(all(ord), a)-ord.begin()-1;
    };
    SegTree dp1(n+1),dp2(n+1);
    fore(i,l,r+1){
        int p = pos(h[i]);
        // cout << p << '\n';
        int dp_i = dp2.query(p, n-1);
        // cout << dp_i << '\n';
        int wtp = pos(h[i] - d);
        // cout << wtp << '\n';
        if(wtp >= 0){
            int bst = dp1.query(0, wtp) + 1;
            // cout << bst << '\n';
            if(bst > dp2.query(wtp, wtp))
                dp2.update(wtp, bst);
        }
        // cout << "FIN\n";
        dp1.update(p, max(1, dp_i));
    }
    return dp1.query(0, r-l+1);
}

컴파일 시 표준 에러 (stderr) 메시지

towers.cpp: In constructor 'SegTree::SegTree(int)':
towers.cpp:40:9: warning: 'SegTree::n' will be initialized after [-Wreorder]
   40 |     int n;
      |         ^
towers.cpp:39:8: warning:   'vi SegTree::st' [-Wreorder]
   39 |     vi st;
      |        ^~
towers.cpp:41:5: warning:   when initialized here [-Wreorder]
   41 |     SegTree(int n): n(n), st(4*n+4, 0) {}
      |     ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...