Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
using namespace std; const int maxn = 1e5 + 10; vector
segment_tree[3 * maxn]; int arr[maxn]; void build(int L, int R, int position) { if(L == R) { segment_tree[position].push_back(arr[L]); } else { int mid = (L + R) / 2; build(L, mid, 2 * position); build(mid + 1, R, 2 * position + 1); merge(segment_tree[2 * position].begin(), segment_tree[2 * position].end(), segment_tree[2 * position + 1].begin(), segment_tree[2 * position + 1].end(), back_inserter(segment_tree[position])); } } int query(int L, int R, int position, int i, int j, int x) { // L R i L R j L R if(i <= L and R <= j) { int idx = lower_bound(segment_tree[position].begin(), segment_tree[position].end(), x) - segment_tree[position].begin(); if(idx >= 0 and idx < segment_tree[position].size()) { if(segment_tree[position][idx] == x) { return 1; } } return 0; } if(R < i or j < L) { return 0; } int mid = (L + R) / 2; return max(query(L, mid, 2 * position, i, j, x), query(mid + 1, R, 2 * position + 1, i, j, x)); } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> arr[i]; } build(0, n, 1); while(true) { int i, j, x; cin >> i >> j >> x; cout << query(0, n, 1, i - 1, j - 1, x) << endl; } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)