結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー aradarad
提出日時 2024-02-23 22:04:39
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 712 ms / 2,500 ms
コード長 2,775 bytes
コンパイル時間 6,561 ms
コンパイル使用メモリ 327,748 KB
実行使用メモリ 32,656 KB
最終ジャッジ日時 2024-02-23 22:05:08
合計ジャッジ時間 22,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 185 ms
14,508 KB
testcase_03 AC 36 ms
6,676 KB
testcase_04 AC 256 ms
20,384 KB
testcase_05 AC 209 ms
17,152 KB
testcase_06 AC 110 ms
10,360 KB
testcase_07 AC 227 ms
17,404 KB
testcase_08 AC 80 ms
9,216 KB
testcase_09 AC 512 ms
32,656 KB
testcase_10 AC 530 ms
32,656 KB
testcase_11 AC 519 ms
32,656 KB
testcase_12 AC 529 ms
32,656 KB
testcase_13 AC 498 ms
32,656 KB
testcase_14 AC 530 ms
32,656 KB
testcase_15 AC 505 ms
32,656 KB
testcase_16 AC 678 ms
32,656 KB
testcase_17 AC 650 ms
32,656 KB
testcase_18 AC 712 ms
32,656 KB
testcase_19 AC 650 ms
32,656 KB
testcase_20 AC 666 ms
32,656 KB
testcase_21 AC 691 ms
32,656 KB
testcase_22 AC 706 ms
32,656 KB
testcase_23 AC 492 ms
32,656 KB
testcase_24 AC 519 ms
32,656 KB
testcase_25 AC 498 ms
32,656 KB
testcase_26 AC 550 ms
32,656 KB
testcase_27 AC 498 ms
32,656 KB
testcase_28 AC 499 ms
32,656 KB
testcase_29 AC 518 ms
32,656 KB
testcase_30 AC 629 ms
32,656 KB
testcase_31 AC 498 ms
32,656 KB
testcase_32 AC 376 ms
21,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using P = pair<ll,ll>;
using VP = vector<P>;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define out(x) cout << x << endl
#define dout(x) cout << fixed << setprecision(10) << x << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)(x.size())
#define re0 return 0
#define pcnt __builtin_popcountll
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int inf = 1e9;
constexpr ll INF = 1e18;
//using mint = modint1000000007;
//using mint = modint998244353;
int di[4] = {1,0,-1,0};
int dj[4] = {0,1,0,-1};

// Coodinate Compression
// https://youtu.be/fR3W5IcBGLQ?t=8550
template<typename T=int>
struct CC {
  bool initialized;
  vector<T> xs;
  CC(): initialized(false) {}
  void add(T x) { xs.push_back(x);}
  void init() {
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    initialized = true;
  }
  int operator()(T x) {
    if (!initialized) init();
    return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
  }
  T operator[](int i) {
    if (!initialized) init();
    return xs[i];
  }
  int size() {
    if (!initialized) init();
    return xs.size();
  }
};

void solve(){
    ll n,a;
    cin >> n >> a;
    CC cc;
    VL x(n);
    rep(i,n){
        cin >> x[i];
        cc.add(x[i]);
    }
    ll t;
    cin >> t;
    VL l(t),r(t);
    rep(i,t){
        cin >> l[i] >> r[i];
        cc.add(l[i]);
        cc.add(r[i]);
    }
    cc.init();
    map<ll,VL> mp;
    rep(i,n){
        mp[cc(x[i])].emplace_back(i);
        x[i] = cc(x[i]);
    }
    rep(i,t){
        l[i] = cc(l[i]);
        r[i] = cc(r[i]);
    }
    ll m = sz(cc.xs);
    set<ll> st;
    rep(i,m+1) st.insert(i);
    VL ans(n,-1);
    for(ll i = t-1;i >= 0;i--){
        ll now = l[i];
        if(!st.count(now)){
            auto itr = st.lower_bound(now);
            now = *itr;
        }
        while(now <= r[i]){
            if(mp.count(now)){
                for(auto tmp:mp[now]) ans[tmp] = i+1;
            }
            st.erase(now);
            now++;
            if(st.count(now)) continue;
            else {
                auto itr = st.lower_bound(now);
                now = *itr;
            }
        }
    }
    rep(i,n) out(ans[i]);
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t = 1;
    rep(ti,t) solve();
}
0