# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088168 | quangminh412 | Garaža (COCI17_garaza) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
/*
John Watson
https://codeforces.com/profile/quangminh98
Mua Code nhu mua Florentino !!
*/
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const int oo = 1e9;
const int maxn = 3009;
int n, k, q;
int arr[maxn];
struct SegmentTree
{
struct Node
{
int l, r, finals;
Node() = default;
Node(int val) : l(val), r(val), finals(0) {}
Node operator + (const Node &other)
{
if (l == oo) return other;
if (other.l == oo) return *this;
Node res;
res.l = l;
res.r = other.r;
res.finals = max({finals, other.finals, int(r == other.l)});
return res;
}
};
vector<Node> st;
int n;
SegmentTree(int n) : n(n) { st.resize(4 * n + 5); build(1, 1, n); }
void build(int head, int l, int r)
{
if (l == r)
{
st[head] = Node(arr[l]);
return;
}
int mid = l + r >> 1;
build(2 * head, l, mid);
build(2 * head + 1, mid + 1, r);
st[head] = st[2 * head] + st[2 * head + 1];
}
Node query(int head, int l, int r, int u, int v)
{
if (l > v || r < u) return Node(oo);
if (u <= l && r <= v) return st[head];
int mid = l + r >> 1;
return query(2 * head, l, mid, u, v) + query(2 * head + 1, mid + 1, r, u, v);
}
int query(int u, int v) { return query(1, 1, n, u, v).finals; }
};
vector<int> adj[4000];
signed main()
{
if (fopen("test.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
faster();
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) cin >> arr[i];
if (k == 2)
{
SegmentTree seg(n);
while (q--)
{
int u, v; cin >> u >> v;
int ans = seg.query(u, v);
cout << (ans == 1 ? "NO\n" : "YES\n");
}
return 0;
}
SegmentTree seg(n);
while (q--)
{
int u, v; cin >> u >> v;
unordered_map<int, int> mp;
int cur = 0;
for (int i = u; i < v; i++)
{
if (mp[arr[i]] == 0) mp[arr[i]] = ++cur;
if (mp[arr[i + 1]] == 0) mp[arr[i]] = ++cur;
int par = i - u;
if (par % 2 == 0)
}
}
return 0;
}