結果

問題 No.3705 ビバ子とマカロン (Bibako and Macaron)
コンテスト
ユーザー Rumain831
提出日時 2026-09-11 00:37:00
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 909 ms / 3,000 ms
+ 362µs
コード長 1,645 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,111 ms
コンパイル使用メモリ 179,804 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2026-09-11 00:37:40
合計ジャッジ時間 32,660 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
小課題1 10 % AC * 5
小課題2 30 % AC * 8
小課題3 60 % AC * 15
合計 100 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;

template<class Tr=int>
struct segtree{
  int N;
  Tr iden;
  vector<Tr> tree;
 
  Tr op(Tr a, Tr b){return min(a, b);}
  
  int pow2(int n){
    int ans=1;
    while(ans<n) ans*=2;
    return ans;
  }

  //aの型に注意
  void build(vector<Tr> &a){
    int n=a.size();
    N=pow2(n);
    iden=1e9;
    tree.resize(2*N, iden);
    for(int i=0; i<n; i++) tree[N+i]=a[i];
    for(int i=N-1; i>=1; i--) tree[i]=op(tree[2*i], tree[2*i+1]);
  }

  void update(int node, Tr x){  //0-indexed
    int i=node+N;
    tree[i]=op(tree[i], x); i/=2;
    while(i>0){
      tree[i]=op(tree[2*i], tree[2*i+1]); i/=2;
    }
    return;
  }

  Tr query(int s, int t){  //0-indexed
    int left=s+N, right=t+N;
    Tr ansl=iden, ansr=iden;
    while(left<=right){
      if(left%2==1){
        ansl=op(ansl, tree[left]); left++;
      }
      if(right%2==0){
        ansr=op(tree[right], ansr); right--;
      }
      left/=2, right/=2;
    }
    return op(ansl, ansr);
  }
};


int main(void){
  int n; cin >> n;
  vector<int> cnt(n+1);
  for(int i=0; i<n; i++){
    int a; cin >> a;
    cnt[a]++;
  }
  segtree seg;
  seg.build(cnt);
  int q; cin >> q;
  while(q--){
    int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2;
    int x=seg.query(l1, r1);
    int y=seg.query(l2, r2);
    if(x<1||y<1){
      cout << "No" << '\n'; continue;
    }
    int l=max(l1, l2), r=min(r1, r2);
    if(l<=r){
      int z=seg.query(l, r);
      if(z<2){
        cout << "No" << '\n'; continue;
      }
    }
    cout << "Yes" << '\n';
  }
  return 0; 
}
0