problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct point {
int left, right, block, id;
};
bool cmp(const point &lhs, const point &rhs) {
if (lhs.block < rhs.block)
return true;
else if (lhs.block > rhs.block)
return false;
else
return lhs.right < rhs.right;
}
int main() {
int n, q;
scanf("%d", &n);
cin >> q;
vector<int> A(n);
for (int i = 0; i < n; i++)
scanf("%d", &A[i]);
int block_size = 450;
vector<point> query(q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &query[i].left, &query[i].right);
query[i].left--, query[i].right--;
query[i].block = query[i].left / block_size;
query[i].id = i;
}
sort(query.begin(), query.end(), cmp);
vector<int> solution(q);
vector<int> hash(1000100);
int left = 0, right = 0, answer = 1;
hash[A[0]] = 1;
for (const point &task : query) {
while (left < task.left) {
hash[A[left]]--;
answer -= (hash[A[left]] == 0);
left++;
}
while (left > task.left) {
left--;
hash[A[left]]++;
answer += (hash[A[left]] == 1);
}
while (right < task.right) {
right++;
hash[A[right]]++;
answer += (hash[A[right]] == 1);
}
while (right > task.right) {
hash[A[right]]--;
answer -= (hash[A[right]] == 0);
right--;
}
solution[task.id] = answer;
}
for (int answer : solution)
printf("%d\n", answer);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct point {
int left, right, block, id;
};
bool cmp(const point &lhs, const point &rhs) {
if (lhs.block < rhs.block)
return true;
else if (lhs.block > rhs.block)
return false;
else
return lhs.right < rhs.right;
}
int main() {
int n, q;
scanf("%d", &n);
cin >> q;
vector<int> A(n);
for (int i = 0; i < n; i++)
scanf("%d", &A[i]);
int block_size = 707;
vector<point> query(q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &query[i].left, &query[i].right);
query[i].left--, query[i].right--;
query[i].block = query[i].left / block_size;
query[i].id = i;
}
sort(query.begin(), query.end(), cmp);
vector<int> solution(q);
vector<int> hash(1000100);
int left = 0, right = 0, answer = 1;
hash[A[0]] = 1;
for (const point &task : query) {
while (left < task.left) {
hash[A[left]]--;
answer -= (hash[A[left]] == 0);
left++;
}
while (left > task.left) {
left--;
hash[A[left]]++;
answer += (hash[A[left]] == 1);
}
while (right < task.right) {
right++;
hash[A[right]]++;
answer += (hash[A[right]] == 1);
}
while (right > task.right) {
hash[A[right]]--;
answer -= (hash[A[right]] == 0);
right--;
}
solution[task.id] = answer;
}
for (int answer : solution)
printf("%d\n", answer);
return 0;
}
| replace | 25 | 26 | 25 | 26 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, Q, K, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 58);
int main() {
class BIT {
ll n;
vector<ll> bitree;
public:
BIT(unsigned long _n) : bitree(_n + 1, 0) { n = _n; }
void add(ll id, ll x) {
while (id <= n) {
bitree[id] += x;
id += id & -id;
}
return;
}
ll sum(ll id) {
ll temp = 0;
while (id > 0) {
temp += bitree[id];
id -= id & -id;
}
return temp;
}
};
cin >> N >> Q;
vec c(N), l(Q), r(Q), ord(Q + 1), ans(Q);
rep(i, N) cin >> c[i];
rep(i, Q) {
cin >> l[i] >> r[i];
--l[i];
ord[i] = i;
}
ord[Q] = Q;
l.push_back(-1);
r.push_back(-1);
sort(ALL(ord), [&](int x, int y) { return l[x] > l[y]; });
vector<set<ll>> col(N);
BIT bit(N + 10);
ll i = 0;
Rrep(L, N) {
if (!col[c[L]].empty()) {
bit.add(*col[c[L]].begin(), 1);
}
col[c[L]].insert(L);
while (l[ord[i]] == L) {
ll id = ord[i];
ans[id] = r[id] - l[id] - bit.sum(r[id] - 1);
++i;
}
}
rep(j, Q) { cout << ans[j] << endl; }
}
| #include <bits/stdc++.h>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, Q, K, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 58);
int main() {
class BIT {
ll n;
vector<ll> bitree;
public:
BIT(unsigned long _n) : bitree(_n + 1, 0) { n = _n; }
void add(ll id, ll x) {
while (id <= n) {
bitree[id] += x;
id += id & -id;
}
return;
}
ll sum(ll id) {
ll temp = 0;
while (id > 0) {
temp += bitree[id];
id -= id & -id;
}
return temp;
}
};
cin >> N >> Q;
vec c(N), l(Q), r(Q), ord(Q + 1), ans(Q);
rep(i, N) {
cin >> c[i];
--c[i];
}
rep(i, Q) {
cin >> l[i] >> r[i];
--l[i];
ord[i] = i;
}
ord[Q] = Q;
l.push_back(-1);
r.push_back(-1);
sort(ALL(ord), [&](int x, int y) { return l[x] > l[y]; });
vector<set<ll>> col(N);
BIT bit(N + 10);
ll i = 0;
Rrep(L, N) {
if (!col[c[L]].empty()) {
bit.add(*col[c[L]].begin(), 1);
}
col[c[L]].insert(L);
while (l[ord[i]] == L) {
ll id = ord[i];
ans[id] = r[id] - l[id] - bit.sum(r[id] - 1);
++i;
}
}
rep(j, Q) { cout << ans[j] << endl; }
}
| replace | 45 | 46 | 45 | 49 | 0 | |
p02599 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main(void) {
int n, q;
cin >> n >> q;
VI a(n);
REP(i, n) a[i] = in();
VI left(q), right(q);
REP(i, q) {
scanf("%d %d", &left[i], &right[i]);
left[i]--;
right[i];
}
int width = sqrt(n);
VI ord(q);
REP(i, q) ord[i] = i;
sort(begin(ord), end(ord), [&](int a, int b) {
if (left[a] / width != left[b] / width)
return left[a] < left[b];
return right[a] < right[b];
});
VI ans(q);
int cnt = 0;
map<int, int> mp;
int x = 0, y = 0;
REP(j, q) {
int i = ord[j];
while (x > left[i]) {
x--;
mp[a[x]]++;
if (mp[a[x]] == 1)
cnt++;
}
while (y < right[i]) {
mp[a[y]]++;
if (mp[a[y]] == 1)
cnt++;
y++;
}
while (x < left[i]) {
mp[a[x]]--;
if (mp[a[x]] == 0)
cnt--;
x++;
}
while (y > right[i]) {
y--;
mp[a[y]]--;
if (mp[a[y]] == 0)
cnt--;
}
ans[i] = cnt;
}
REP(i, q) printf("%d\n", ans[i]);
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main(void) {
int n, q;
cin >> n >> q;
VI a(n);
REP(i, n) a[i] = in();
VI left(q), right(q);
REP(i, q) {
scanf("%d %d", &left[i], &right[i]);
left[i]--;
right[i];
}
int width = sqrt(n);
VI ord(q);
REP(i, q) ord[i] = i;
sort(begin(ord), end(ord), [&](int a, int b) {
if (left[a] / width != left[b] / width)
return left[a] < left[b];
return right[a] < right[b];
});
VI ans(q);
int cnt = 0;
VI mp(n + 1);
int x = 0, y = 0;
REP(j, q) {
int i = ord[j];
while (x > left[i]) {
x--;
mp[a[x]]++;
if (mp[a[x]] == 1)
cnt++;
}
while (y < right[i]) {
mp[a[y]]++;
if (mp[a[y]] == 1)
cnt++;
y++;
}
while (x < left[i]) {
mp[a[x]]--;
if (mp[a[x]] == 0)
cnt--;
x++;
}
while (y > right[i]) {
y--;
mp[a[y]]--;
if (mp[a[y]] == 0)
cnt--;
}
ans[i] = cnt;
}
REP(i, q) printf("%d\n", ans[i]);
return 0;
}
| replace | 76 | 77 | 76 | 77 | TLE | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int A[500000], K[500001], k = 1, CL = 0, CR = -1, n, B;
void add(int I) {
K[A[I]]++;
if (K[A[I]] == 1) {
k++;
}
}
void Remove(int I) {
K[A[I]]--;
if (K[A[I]] == 0) {
k--;
}
}
int query(int L, int R) {
while (CL < L) {
Remove(CL);
CL++;
}
while (CL > L) {
CL--;
add(CL);
}
while (CR < R) {
CR++;
add(CR);
}
while (CR > R) {
Remove(CR);
CR--;
}
return k;
}
bool Bsort(const pair<pair<int, int>, int> &a,
const pair<pair<int, int>, int> &b) {
if (a.first.first / B == b.first.first / B) {
return a.first.second < b.first.second;
} else {
return a.first.first / B < b.first.first / B;
}
}
int main() {
int m, l, r, L, R, p, I;
cin >> n >> m;
B = sqrt(n);
map<int, int> M;
for (int i = 0; i < n; i++) {
cin >> A[i];
if (M[A[i]] == 0) {
M[A[i]] = k;
k++;
K[A[i]] = 0;
}
A[i] = M[A[i]];
}
k = 0;
int U[m];
vector<pair<pair<int, int>, int>> V;
for (int i = 0; i < m; i++) {
cin >> l >> r;
l--;
r--;
V.push_back({{l, r}, i});
}
sort(V.begin(), V.end(), Bsort);
for (int i = 0; i < m; i++) {
L = V[i].first.first;
R = V[i].first.second;
I = V[i].second;
U[I] = query(L, R);
}
for (int i = 0; i < m; i++) {
cout << U[i] << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int A[500000], K[500001], k = 1, CL = 0, CR = -1, n, B;
void add(int I) {
K[A[I]]++;
if (K[A[I]] == 1) {
k++;
}
}
void Remove(int I) {
K[A[I]]--;
if (K[A[I]] == 0) {
k--;
}
}
int query(int L, int R) {
while (CL < L) {
Remove(CL);
CL++;
}
while (CL > L) {
CL--;
add(CL);
}
while (CR < R) {
CR++;
add(CR);
}
while (CR > R) {
Remove(CR);
CR--;
}
return k;
}
bool Bsort(const pair<pair<int, int>, int> &a,
const pair<pair<int, int>, int> &b) {
if (a.first.first / B == b.first.first / B) {
return a.first.second < b.first.second;
} else {
return a.first.first / B < b.first.first / B;
}
}
int main() {
int m, l, r, L, R, p, I;
cin >> n >> m;
B = sqrt(n);
map<int, int> M;
for (int i = 0; i < n; i++) {
cin >> A[i];
if (M[A[i]] == 0) {
M[A[i]] = k;
k++;
K[A[i]] = 0;
}
A[i] = M[A[i]];
}
k = 0;
int U[m];
vector<pair<pair<int, int>, int>> V;
for (int i = 0; i < m; i++) {
cin >> l >> r;
l--;
r--;
V.push_back({{l, r}, i});
}
sort(V.begin(), V.end(), Bsort);
for (int i = 0; i < m; i++) {
L = V[i].first.first;
R = V[i].first.second;
I = V[i].second;
U[I] = query(L, R);
}
for (int i = 0; i < m; i++) {
cout << U[i] << "\n";
}
return 0;
}
| insert | 1 | 1 | 1 | 2 | TLE | |
p02599 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void prec(const int &DIG) {
cout << fixed << setprecision(DIG);
cerr << fixed << setprecision(DIG);
}
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
const ll INF = 1e18; // LONG_LONG_MAX;
// const int INF = INT_MAX;
const ll MOD = 1000000007; // 998244353;
// Fenwick Tree
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type, std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t,
unsigned __int128>;
template <class T>
using is_integral =
typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_signed_int =
typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value, make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using to_unsigned =
typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
using U = internal::to_unsigned_t<T>;
public:
fenwick_tree() : _n(0) {}
fenwick_tree(int n) : _n(n), data(n) {}
void add(int p, T x) {
assert(0 <= p && p < _n);
p++;
while (p <= _n) {
data[p - 1] += U(x);
p += p & -p;
}
}
T sum(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
return sum(r) - sum(l);
}
private:
int _n;
std::vector<U> data;
U sum(int r) {
U s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
};
} // namespace atcoder
using namespace atcoder;
struct Query {
int l, r, i;
};
bool comp_r(Query &x, Query &y) { return x.r < y.r; }
// bool comp_i(static Query &x, static Query &y) { return x.i < y.i; }
int main() {
// 色は1-indのまま,位置は0-indに直す
int N, Q;
cin >> N >> Q;
vi c(N);
rep(i, N) cin >> c[i];
vector<Query> q;
rep(i, Q) {
int l, r;
cin >> l >> r;
q.push_back(Query{l - 1, r - 1, i});
}
sort(all(q), comp_r);
vi ans(Q);
map<int, int> last; // last[i]:最も右にある色iの玉の座標
fenwick_tree<int> fw(N);
int cur = 0, i = 0;
while (cur < N) {
if (cur < q[i].r) {
if (last.count(c[cur]))
fw.add(last[c[cur]], -1);
fw.add(cur, 1);
last[c[cur]] = cur;
cur++;
} else if (cur == q[i].r) {
if (last.count(c[cur]))
fw.add(last[c[cur]], -1);
fw.add(cur, 1);
last[c[cur]] = cur;
ans[q[i].i] = fw.sum(q[i].l, q[i].r + 1);
i++;
} else if (cur > q[i].r) {
i++;
}
}
rep(i, Q) cout << ans[i] << endl;
} | // #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void prec(const int &DIG) {
cout << fixed << setprecision(DIG);
cerr << fixed << setprecision(DIG);
}
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
const ll INF = 1e18; // LONG_LONG_MAX;
// const int INF = INT_MAX;
const ll MOD = 1000000007; // 998244353;
// Fenwick Tree
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type, std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t,
unsigned __int128>;
template <class T>
using is_integral =
typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_signed_int =
typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value, make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type, std::false_type>::type;
template <class T>
using to_unsigned =
typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
using U = internal::to_unsigned_t<T>;
public:
fenwick_tree() : _n(0) {}
fenwick_tree(int n) : _n(n), data(n) {}
void add(int p, T x) {
assert(0 <= p && p < _n);
p++;
while (p <= _n) {
data[p - 1] += U(x);
p += p & -p;
}
}
T sum(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
return sum(r) - sum(l);
}
private:
int _n;
std::vector<U> data;
U sum(int r) {
U s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
};
} // namespace atcoder
using namespace atcoder;
struct Query {
int l, r, i;
};
bool comp_r(Query &x, Query &y) { return x.r < y.r; }
// bool comp_i(static Query &x, static Query &y) { return x.i < y.i; }
int main() {
// 色は1-indのまま,位置は0-indに直す
int N, Q;
cin >> N >> Q;
vi c(N);
rep(i, N) cin >> c[i];
vector<Query> q;
rep(i, Q) {
int l, r;
cin >> l >> r;
q.push_back(Query{l - 1, r - 1, i});
}
sort(all(q), comp_r);
vi ans(Q);
map<int, int> last; // last[i]:最も右にある色iの玉の座標
fenwick_tree<int> fw(N);
int cur = 0, i = 0;
while (cur < N and i < Q) {
if (cur < q[i].r) {
if (last.count(c[cur]))
fw.add(last[c[cur]], -1);
fw.add(cur, 1);
last[c[cur]] = cur;
cur++;
} else if (cur == q[i].r) {
if (last.count(c[cur]))
fw.add(last[c[cur]], -1);
fw.add(cur, 1);
last[c[cur]] = cur;
ans[q[i].i] = fw.sum(q[i].l, q[i].r + 1);
i++;
} else if (cur > q[i].r) {
i++;
}
}
rep(i, Q) cout << ans[i] << endl;
} | replace | 216 | 217 | 216 | 217 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename T> class FenwickTree {
private:
int n, mx;
vector<T> bit;
public:
FenwickTree(int sz) : n(sz + 1), mx(1), bit(n, 0) {
while (mx * 2 <= n)
mx *= 2;
}
FenwickTree(const vector<T> &v) : n((int)v.size() + 1), mx(1), bit(n, 0) {
for (int i = 0; i < n - 1; i++)
add(i, v.at(i));
while (mx * 2 <= n)
mx *= 2;
}
void add(int i, T x) {
i++;
while (i < n)
bit.at(i) += x, i += i & -i;
}
void add(int l, int r, T x) {
add(l, x);
add(r + 1, -x);
}
T sum(int i) {
i++;
T ret = 0;
while (i > 0)
ret += bit.at(i), i -= i & -i;
return ret;
}
T sum(int l, int r) { return sum(r) - sum(l - 1); }
int lower_bound(T w) {
if (w <= 0)
return 0;
int x = 0;
for (int k = mx; k > 0; k /= 2) {
if (x + k <= n - 1 && bit.at(x + k) < w) {
w -= bit.at(x + k);
x += k;
}
}
return x;
}
int upper_bound(T w) {
if (w < 0)
return 0;
int x = 0;
for (int k = mx; k > 0; k /= 2) {
if (x + k <= n - 1 && bit.at(x + k) <= w) {
w -= bit.at(x + k);
x += k;
}
}
return x;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
vector<int> C(N);
for (int i = 0; i < N; i++)
cin >> C.at(i);
vector<vector<pair<int, int>>> V(N);
for (int i = 0, l, r; cin >> l >> r; i++) {
V.at(--r).push_back({--l, i});
}
FenwickTree<int> FT(N);
vector<int> ans(Q);
vector<int> pre(N, -1);
for (int r = 0; r < N; r++) {
if (pre.at(C.at(r)) >= 0)
FT.add(pre.at(C.at(r)), -1);
pre.at(C.at(r)) = r;
FT.add(r, 1);
for (auto [l, i] : V.at(r))
ans.at(i) = FT.sum(l, r);
}
for (auto a : ans)
cout << a << "\n";
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> class FenwickTree {
private:
int n, mx;
vector<T> bit;
public:
FenwickTree(int sz) : n(sz + 1), mx(1), bit(n, 0) {
while (mx * 2 <= n)
mx *= 2;
}
FenwickTree(const vector<T> &v) : n((int)v.size() + 1), mx(1), bit(n, 0) {
for (int i = 0; i < n - 1; i++)
add(i, v.at(i));
while (mx * 2 <= n)
mx *= 2;
}
void add(int i, T x) {
i++;
while (i < n)
bit.at(i) += x, i += i & -i;
}
void add(int l, int r, T x) {
add(l, x);
add(r + 1, -x);
}
T sum(int i) {
i++;
T ret = 0;
while (i > 0)
ret += bit.at(i), i -= i & -i;
return ret;
}
T sum(int l, int r) { return sum(r) - sum(l - 1); }
int lower_bound(T w) {
if (w <= 0)
return 0;
int x = 0;
for (int k = mx; k > 0; k /= 2) {
if (x + k <= n - 1 && bit.at(x + k) < w) {
w -= bit.at(x + k);
x += k;
}
}
return x;
}
int upper_bound(T w) {
if (w < 0)
return 0;
int x = 0;
for (int k = mx; k > 0; k /= 2) {
if (x + k <= n - 1 && bit.at(x + k) <= w) {
w -= bit.at(x + k);
x += k;
}
}
return x;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
vector<int> C(N);
for (int i = 0; i < N; i++)
cin >> C.at(i);
vector<vector<pair<int, int>>> V(N);
for (int i = 0, l, r; cin >> l >> r; i++) {
V.at(--r).push_back({--l, i});
}
FenwickTree<int> FT(N);
vector<int> ans(Q);
vector<int> pre(N + 1, -1);
for (int r = 0; r < N; r++) {
if (pre.at(C.at(r)) >= 0)
FT.add(pre.at(C.at(r)), -1);
pre.at(C.at(r)) = r;
FT.add(r, 1);
for (auto [l, i] : V.at(r))
ans.at(i) = FT.sum(l, r);
}
for (auto a : ans)
cout << a << "\n";
} | replace | 78 | 79 | 78 | 79 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1LL << 60;
const int INF = 1LL << 17;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll bit[500500];
ll n;
#define N 500010
ll sum(ll i) {
ll res = 0;
while (0 < i) {
res += bit[i];
i -= i & -i;
}
return res;
}
void add(ll i, ll x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
ll rsum(ll l, ll r) { return sum(r) - sum(l - 1); }
vector<vector<ll>> qr(N), qri(N);
int main() {
ll q;
cin >> n >> q;
vector<ll> c(n + 1);
rep(i, n) cin >> c[i + 1];
vector<ll> a(N);
rep(i, q) {
ll a, b;
cin >> a >> b;
qr[b].push_back(a);
qri[b].push_back(i);
}
vector<ll> res(n + 1);
FOR(i, 1, n + 1) {
if (a[c[i]] > 0)
add(a[c[i]], -1);
add(i, 1);
a[c[i]] = i;
rep(j, qr[i].size()) { res[qri[i][j]] = rsum(qr[i][j], i); }
}
rep(i, q) cout << res[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1LL << 60;
const int INF = 1LL << 17;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll bit[500500];
ll n;
#define N 500010
ll sum(ll i) {
ll res = 0;
while (0 < i) {
res += bit[i];
i -= i & -i;
}
return res;
}
void add(ll i, ll x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
ll rsum(ll l, ll r) { return sum(r) - sum(l - 1); }
vector<vector<ll>> qr(N), qri(N);
int main() {
ll q;
cin >> n >> q;
vector<ll> c(n + 1);
rep(i, n) cin >> c[i + 1];
vector<ll> a(N);
rep(i, q) {
ll a, b;
cin >> a >> b;
qr[b].push_back(a);
qri[b].push_back(i);
}
vector<ll> res(q + 1);
FOR(i, 1, n + 1) {
if (a[c[i]] > 0)
add(a[c[i]], -1);
add(i, 1);
a[c[i]] = i;
rep(j, qr[i].size()) { res[qri[i][j]] = rsum(qr[i][j], i); }
}
rep(i, q) cout << res[i] << endl;
}
| replace | 54 | 55 | 54 | 55 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 30010;
const int S = 200010;
int arr[N];
int L[S];
int R[S];
int seg[4 * N];
int ans[S];
vector<pair<pair<int, int>, int>> Q;
map<int, int> lst;
bool cmp(pair<pair<int, int>, int> A, pair<pair<int, int>, int> B) {
if (A.first.second == B.first.second)
return A.first.first < B.first.first;
return A.first.second < B.first.second;
}
void update(int pos, int val, int st, int en, int idx) {
if (st == en && st == pos) {
seg[idx] = val;
return;
}
int mid = st + (en - st) / 2;
if (pos <= mid)
update(pos, val, st, mid, 2 * idx);
else
update(pos, val, mid + 1, en, 2 * idx + 1);
seg[idx] = seg[2 * idx] + seg[2 * idx + 1];
}
long long query(int l, int r, int st, int en, int idx) {
// cout<<l<<" "<<r<<endl;
if (l > en || r < st || st > en)
return 0;
if (l <= st && r >= en)
return seg[idx];
int mid = st + (en - st) / 2;
return query(l, r, st, mid, 2 * idx) + query(l, r, mid + 1, en, 2 * idx + 1);
}
int main() {
ios_base::sync_with_stdio(0);
int n, q, l, r;
// cin>>n;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
// cin>>arr[i];
for (int i = 0; i < q; i++) {
// cin>>l>>r;
scanf("%d%d", &l, &r);
l--, r--;
L[i] = l;
R[i] = r;
Q.push_back({{l, r}, i});
}
sort(Q.begin(), Q.end(), cmp);
memset(seg, 0, sizeof(seg));
int j = 0;
int pos;
for (int i = 0; i < n; i++) {
pos = Q[j].second;
l = L[pos];
r = R[pos];
if (lst.count(arr[i]) > 0)
update(lst[arr[i]], 0, 0, n - 1, 1);
update(i, 1, 0, n - 1, 1);
lst[arr[i]] = i;
while (r == i && j < q) {
ans[pos] = query(l, r, 0, n - 1, 1);
j++;
if (j == q)
break;
pos = Q[j].second;
l = L[pos];
r = R[pos];
}
}
for (int i = 0; i < q; i++)
printf("%d\n", ans[i]);
// cout<<ans[i]<<"\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 2;
const int S = 5e5 + 2;
int arr[N];
int L[S];
int R[S];
int seg[4 * N];
int ans[S];
vector<pair<pair<int, int>, int>> Q;
map<int, int> lst;
bool cmp(pair<pair<int, int>, int> A, pair<pair<int, int>, int> B) {
if (A.first.second == B.first.second)
return A.first.first < B.first.first;
return A.first.second < B.first.second;
}
void update(int pos, int val, int st, int en, int idx) {
if (st == en && st == pos) {
seg[idx] = val;
return;
}
int mid = st + (en - st) / 2;
if (pos <= mid)
update(pos, val, st, mid, 2 * idx);
else
update(pos, val, mid + 1, en, 2 * idx + 1);
seg[idx] = seg[2 * idx] + seg[2 * idx + 1];
}
long long query(int l, int r, int st, int en, int idx) {
// cout<<l<<" "<<r<<endl;
if (l > en || r < st || st > en)
return 0;
if (l <= st && r >= en)
return seg[idx];
int mid = st + (en - st) / 2;
return query(l, r, st, mid, 2 * idx) + query(l, r, mid + 1, en, 2 * idx + 1);
}
int main() {
ios_base::sync_with_stdio(0);
int n, q, l, r;
// cin>>n;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
// cin>>arr[i];
for (int i = 0; i < q; i++) {
// cin>>l>>r;
scanf("%d%d", &l, &r);
l--, r--;
L[i] = l;
R[i] = r;
Q.push_back({{l, r}, i});
}
sort(Q.begin(), Q.end(), cmp);
memset(seg, 0, sizeof(seg));
int j = 0;
int pos;
for (int i = 0; i < n; i++) {
pos = Q[j].second;
l = L[pos];
r = R[pos];
if (lst.count(arr[i]) > 0)
update(lst[arr[i]], 0, 0, n - 1, 1);
update(i, 1, 0, n - 1, 1);
lst[arr[i]] = i;
while (r == i && j < q) {
ans[pos] = query(l, r, 0, n - 1, 1);
j++;
if (j == q)
break;
pos = Q[j].second;
l = L[pos];
r = R[pos];
}
}
for (int i = 0; i < q; i++)
printf("%d\n", ans[i]);
// cout<<ans[i]<<"\n";
return 0;
}
| replace | 2 | 4 | 2 | 4 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int val;
bool comp(vector<int> &v1, vector<int> &v2) {
int l1 = v1[0] / val;
int l2 = v2[0] / val;
if (l1 != l2)
return (l1 < l2);
return v1[1] < v2[1];
}
int arr[300001];
int main() {
int n, q;
scanf("%d", &n);
scanf("%d", &q);
for (int i = 1; i <= n; i++)
scanf("%d", &arr[i]);
vector<vector<int>> query(q, vector<int>(3));
vector<int> sol(q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &query[i][0], &query[i][1]);
query[i][2] = i;
}
val = sqrt(n);
sort(query.begin(), query.end(), comp);
int l = 1, r = 0, diff = 0;
vector<int> fr(1000001, 0);
for (const auto &x : query) {
while (r > x[1]) {
fr[arr[r]]--;
if (fr[arr[r]] == 0)
diff--;
--r;
}
while (l < x[0]) {
fr[arr[l]]--;
if (fr[arr[l]] == 0)
diff--;
l++;
}
while (r < x[1]) {
++r;
fr[arr[r]]++;
if (fr[arr[r]] == 1)
diff++;
}
while (l > x[0]) {
l--;
fr[arr[l]]++;
if (fr[arr[l]] == 1)
diff++;
}
sol[x[2]] = diff;
}
for (int x : sol)
printf("%d\n", x);
} | #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int val;
bool comp(vector<int> &v1, vector<int> &v2) {
int l1 = v1[0] / val;
int l2 = v2[0] / val;
if (l1 != l2)
return (l1 < l2);
return v1[1] < v2[1];
}
int arr[500001];
int main() {
int n, q;
scanf("%d", &n);
scanf("%d", &q);
for (int i = 1; i <= n; i++)
scanf("%d", &arr[i]);
vector<vector<int>> query(q, vector<int>(3));
vector<int> sol(q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &query[i][0], &query[i][1]);
query[i][2] = i;
}
val = sqrt(n);
sort(query.begin(), query.end(), comp);
int l = 1, r = 0, diff = 0;
vector<int> fr(1000001, 0);
for (const auto &x : query) {
while (r > x[1]) {
fr[arr[r]]--;
if (fr[arr[r]] == 0)
diff--;
--r;
}
while (l < x[0]) {
fr[arr[l]]--;
if (fr[arr[l]] == 0)
diff--;
l++;
}
while (r < x[1]) {
++r;
fr[arr[r]]++;
if (fr[arr[r]] == 1)
diff++;
}
while (l > x[0]) {
l--;
fr[arr[l]]++;
if (fr[arr[l]] == 1)
diff++;
}
sol[x[2]] = diff;
}
for (int x : sol)
printf("%d\n", x);
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 100;
// #define int long long
const int INF = 1e9;
int f[MAXN], last[MAXN];
void add(int i, int x) {
for (; i < MAXN; i = i | (i + 1))
f[i] += x;
}
//[l, r)
int sum(int l, int r) {
int res = 0;
for (int i = r - 1; i > -1; i = (i & (i + 1)) - 1)
res += f[i];
for (int i = l - 1; i > -1; i = (i & (i + 1)) - 1)
res -= f[i];
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> c(n + 1);
for (int i = 1; i <= n; i++)
cin >> c[i];
int l, r;
vector<vector<pair<int, int>>> a(n + 1);
for (int i = 0; i < q; i++) {
cin >> l >> r;
a[r].eb(l, i);
}
vector<int> ans(q);
for (int i = 1; i <= n; i++) {
if (last[c[i]])
add(last[c[i]], -1);
last[c[i]] = i;
add(last[c[i]], 1);
for (auto j : a[i])
ans[j.ss] = sum(j.ff, i + 1);
}
for (auto i : ans)
cout << i << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 5e5 + 5;
// #define int long long
const int INF = 1e9;
int f[MAXN], last[MAXN];
void add(int i, int x) {
for (; i < MAXN; i = i | (i + 1))
f[i] += x;
}
//[l, r)
int sum(int l, int r) {
int res = 0;
for (int i = r - 1; i > -1; i = (i & (i + 1)) - 1)
res += f[i];
for (int i = l - 1; i > -1; i = (i & (i + 1)) - 1)
res -= f[i];
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> c(n + 1);
for (int i = 1; i <= n; i++)
cin >> c[i];
int l, r;
vector<vector<pair<int, int>>> a(n + 1);
for (int i = 0; i < q; i++) {
cin >> l >> r;
a[r].eb(l, i);
}
vector<int> ans(q);
for (int i = 1; i <= n; i++) {
if (last[c[i]])
add(last[c[i]], -1);
last[c[i]] = i;
add(last[c[i]], 1);
for (auto j : a[i])
ans[j.ss] = sum(j.ff, i + 1);
}
for (auto i : ans)
cout << i << '\n';
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long tint;
#define forsn(i, s, n) for (int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO \
ios::sync_with_stdio(0); \
cin.tie(NULL);
#define dbg cout << "hu" << endl;
const tint INF = 11000000;
const int MOD = 1000000007;
const int N = 2e5 + 1;
int t[4 * N];
int n;
map<int, int> id;
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = 0;
} else {
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
t[v] = t[2 * v] + t[2 * v + 1];
}
}
int sum(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return sum(2 * v, tl, tm, l, min(r, tm)) +
sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
}
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr)
t[v] = val;
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(2 * v, tl, tm, pos, val);
else
update(2 * v + 1, tm + 1, tr, pos, val);
t[v] = t[2 * v] + t[2 * v + 1];
}
}
struct Q {
int l, r, id;
bool operator<(const Q &ot) const { return r < ot.r; }
};
int main() {
NACHO;
int q;
cin >> n >> q;
vector<int> a(n);
forn(i, n) {
cin >> a[i];
if (id[a[i]] == 0)
id[a[i]] = int(id.size());
a[i] = id[a[i]];
}
build(1, 0, n - 1);
vector<Q> query(q);
forn(i, q) {
cin >> query[i].l >> query[i].r;
query[i].l--;
query[i].r--;
query[i].id = i;
}
sort(all(query));
vector<int> last(N, -1);
int ret[q];
int contQ = 0;
forn(i, n) {
if (last[a[i]] != -1) {
update(1, 0, n - 1, last[a[i]], 0);
}
last[a[i]] = i;
update(1, 0, n - 1, i, 1);
while (contQ < q && query[contQ].r == i) {
if (query[contQ].l == 0) {
ret[query[contQ].id] = sum(1, 0, n - 1, 0, query[contQ].r);
} else {
ret[query[contQ].id] = sum(1, 0, n - 1, 0, query[contQ].r) -
sum(1, 0, n - 1, 0, query[contQ].l - 1);
}
contQ++;
}
}
forn(i, q) { cout << ret[i] << "\n"; }
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long tint;
#define forsn(i, s, n) for (int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO \
ios::sync_with_stdio(0); \
cin.tie(NULL);
#define dbg cout << "hu" << endl;
const tint INF = 11000000;
const int MOD = 1000000007;
const int N = 5e5 + 5;
int t[4 * N];
int n;
map<int, int> id;
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = 0;
} else {
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
t[v] = t[2 * v] + t[2 * v + 1];
}
}
int sum(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return sum(2 * v, tl, tm, l, min(r, tm)) +
sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
}
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr)
t[v] = val;
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(2 * v, tl, tm, pos, val);
else
update(2 * v + 1, tm + 1, tr, pos, val);
t[v] = t[2 * v] + t[2 * v + 1];
}
}
struct Q {
int l, r, id;
bool operator<(const Q &ot) const { return r < ot.r; }
};
int main() {
NACHO;
int q;
cin >> n >> q;
vector<int> a(n);
forn(i, n) {
cin >> a[i];
if (id[a[i]] == 0)
id[a[i]] = int(id.size());
a[i] = id[a[i]];
}
build(1, 0, n - 1);
vector<Q> query(q);
forn(i, q) {
cin >> query[i].l >> query[i].r;
query[i].l--;
query[i].r--;
query[i].id = i;
}
sort(all(query));
vector<int> last(N, -1);
int ret[q];
int contQ = 0;
forn(i, n) {
if (last[a[i]] != -1) {
update(1, 0, n - 1, last[a[i]], 0);
}
last[a[i]] = i;
update(1, 0, n - 1, i, 1);
while (contQ < q && query[contQ].r == i) {
if (query[contQ].l == 0) {
ret[query[contQ].id] = sum(1, 0, n - 1, 0, query[contQ].r);
} else {
ret[query[contQ].id] = sum(1, 0, n - 1, 0, query[contQ].r) -
sum(1, 0, n - 1, 0, query[contQ].l - 1);
}
contQ++;
}
}
forn(i, q) { cout << ret[i] << "\n"; }
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
int n, m;
struct Tree {
int ls, rs;
ll val; // 左右儿子的编号, 和维护的一个值.
} tre[maxn * 20];
int idx = 0, root[maxn];
int build(int l, int r) {
int nod = ++idx;
tre[nod].val = 0;
if (l == r)
return nod;
int mid = (l + r) >> 1;
tre[nod].ls = build(l, mid);
tre[nod].rs = build(mid + 1, r);
return nod;
}
int update(int pre, int l, int r, int pos, ll v) {
int nod = ++idx;
tre[nod] = tre[pre];
tre[nod].val += v;
if (l == r)
return nod;
int mid = (l + r) >> 1;
if (pos <= mid)
tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
else
tre[nod].rs = update(tre[pre].rs, mid + 1, r, pos, v);
return nod;
}
ll query(int id, int l, int r, int pos) {
if (l == r)
return tre[id].val;
int mid = (l + r) >> 1;
if (pos <= mid) {
return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
} else
return query(tre[id].rs, mid + 1, r, pos);
}
int a[maxn], vis[maxn];
void solve() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
root[0] = build(1, n); // 根节点
for (int i = 1; i <= n; i++) {
if (!vis[a[i]])
root[i] = update(root[i - 1], 1, n, i, 1);
else {
int t = update(root[i - 1], 1, n, vis[a[i]], -1);
root[i] = update(t, 1, n, i, 1);
}
vis[a[i]] = i;
}
while (m--) {
int l, r;
scanf("%d%d", &l, &r);
ll tmp = query(root[r], 1, n, l);
printf("%lld\n", tmp);
}
}
int main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
int n, m;
struct Tree {
int ls, rs;
ll val; // 左右儿子的编号, 和维护的一个值.
} tre[maxn * 100];
int idx = 0, root[maxn];
int build(int l, int r) {
int nod = ++idx;
tre[nod].val = 0;
if (l == r)
return nod;
int mid = (l + r) >> 1;
tre[nod].ls = build(l, mid);
tre[nod].rs = build(mid + 1, r);
return nod;
}
int update(int pre, int l, int r, int pos, ll v) {
int nod = ++idx;
tre[nod] = tre[pre];
tre[nod].val += v;
if (l == r)
return nod;
int mid = (l + r) >> 1;
if (pos <= mid)
tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
else
tre[nod].rs = update(tre[pre].rs, mid + 1, r, pos, v);
return nod;
}
ll query(int id, int l, int r, int pos) {
if (l == r)
return tre[id].val;
int mid = (l + r) >> 1;
if (pos <= mid) {
return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
} else
return query(tre[id].rs, mid + 1, r, pos);
}
int a[maxn], vis[maxn];
void solve() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
root[0] = build(1, n); // 根节点
for (int i = 1; i <= n; i++) {
if (!vis[a[i]])
root[i] = update(root[i - 1], 1, n, i, 1);
else {
int t = update(root[i - 1], 1, n, vis[a[i]], -1);
root[i] = update(t, 1, n, i, 1);
}
vis[a[i]] = i;
}
while (m--) {
int l, r;
scanf("%d%d", &l, &r);
ll tmp = query(root[r], 1, n, l);
printf("%lld\n", tmp);
}
}
int main() {
solve();
return 0;
}
| replace | 8 | 9 | 8 | 9 | -11 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef int ll;
#define N 200000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
vector<ll> a(N + 5), b(N + 5);
vector<ll> segtree[4 * N + 5];
void build(ll ptr, ll start, ll end) {
if (start == end) {
segtree[ptr].push_back(a[start]);
return;
}
ll mid = (start + end) / 2;
build(2 * ptr, start, mid);
build(2 * ptr + 1, mid + 1, end);
ll pointer1 = 0, pointer2 = 0;
while (pointer1 < segtree[2 * ptr].size() &&
pointer2 < segtree[2 * ptr + 1].size()) {
if (segtree[2 * ptr][pointer1] < segtree[2 * ptr + 1][pointer2]) {
segtree[ptr].push_back(segtree[2 * ptr][pointer1]);
pointer1++;
} else {
segtree[ptr].push_back(segtree[2 * ptr + 1][pointer2]);
pointer2++;
}
}
while (pointer1 < segtree[2 * ptr].size()) {
segtree[ptr].push_back(segtree[2 * ptr][pointer1]);
pointer1++;
}
while (pointer2 < segtree[2 * ptr + 1].size()) {
segtree[ptr].push_back(segtree[2 * ptr + 1][pointer2]);
pointer2++;
}
return;
}
ll query(ll ptr, ll l, ll r, ll val, ll start, ll end) {
if (start > r || l > end)
return 0;
else if (start >= l && r >= end) {
ll count = lower_bound(segtree[ptr].begin(), segtree[ptr].end(), val) -
segtree[ptr].begin();
return (segtree[ptr].size() - count);
} else {
ll mid = (start + end) / 2;
return (query(2 * ptr, l, r, val, start, mid) +
query(2 * ptr + 1, l, r, val, mid + 1, end));
}
}
int main() {
IO clock_t begin = clock();
ll n, q;
cin >> n >> q;
map<ll, ll> mp;
for (ll i = 1; i <= n; i++)
cin >> a[i];
for (ll i = 1; i <= n; i++)
b[i] = a[i];
for (ll i = n; i >= 1; i--) {
a[i] = (mp[b[i]] == 0 ? n + 1 : mp[b[i]]);
mp[b[i]] = i;
}
// for(ll i=1;i<=n;i++)
// cout<<a[i]<<' ';
// cout<<endl;
build(1, 1, n);
while (q--) {
ll l, r;
cin >> l >> r;
ll ans = query(1, l, r, r + 1, 1, n);
cout << ans << '\n';
}
// cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 500000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
vector<ll> a(N + 5), b(N + 5);
vector<ll> segtree[4 * N + 5];
void build(ll ptr, ll start, ll end) {
if (start == end) {
segtree[ptr].push_back(a[start]);
return;
}
ll mid = (start + end) / 2;
build(2 * ptr, start, mid);
build(2 * ptr + 1, mid + 1, end);
ll pointer1 = 0, pointer2 = 0;
while (pointer1 < segtree[2 * ptr].size() &&
pointer2 < segtree[2 * ptr + 1].size()) {
if (segtree[2 * ptr][pointer1] < segtree[2 * ptr + 1][pointer2]) {
segtree[ptr].push_back(segtree[2 * ptr][pointer1]);
pointer1++;
} else {
segtree[ptr].push_back(segtree[2 * ptr + 1][pointer2]);
pointer2++;
}
}
while (pointer1 < segtree[2 * ptr].size()) {
segtree[ptr].push_back(segtree[2 * ptr][pointer1]);
pointer1++;
}
while (pointer2 < segtree[2 * ptr + 1].size()) {
segtree[ptr].push_back(segtree[2 * ptr + 1][pointer2]);
pointer2++;
}
return;
}
ll query(ll ptr, ll l, ll r, ll val, ll start, ll end) {
if (start > r || l > end)
return 0;
else if (start >= l && r >= end) {
ll count = lower_bound(segtree[ptr].begin(), segtree[ptr].end(), val) -
segtree[ptr].begin();
return (segtree[ptr].size() - count);
} else {
ll mid = (start + end) / 2;
return (query(2 * ptr, l, r, val, start, mid) +
query(2 * ptr + 1, l, r, val, mid + 1, end));
}
}
int main() {
IO clock_t begin = clock();
ll n, q;
cin >> n >> q;
map<ll, ll> mp;
for (ll i = 1; i <= n; i++)
cin >> a[i];
for (ll i = 1; i <= n; i++)
b[i] = a[i];
for (ll i = n; i >= 1; i--) {
a[i] = (mp[b[i]] == 0 ? n + 1 : mp[b[i]]);
mp[b[i]] = i;
}
// for(ll i=1;i<=n;i++)
// cout<<a[i]<<' ';
// cout<<endl;
build(1, 1, n);
while (q--) {
ll l, r;
cin >> l >> r;
ll ans = query(1, l, r, r + 1, 1, n);
cout << ans << '\n';
}
// cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
return 0;
} | replace | 2 | 4 | 2 | 4 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
class Prints {
private:
class __Prints {
public:
__Prints(const char *sep, const char *term) : sep(sep), term(term) {}
template <class... Args> void operator()(Args &&...args) const {
print(std::forward<Args>(args)...);
}
private:
const char *sep, *term;
void print() const { std::cout << term; }
void print_rest() const { std::cout << term; }
template <class T, class... Tail>
void print(T &&head, Tail &&...tail) const {
std::cout << head, print_rest(std::forward<Tail>(tail)...);
}
template <class T, class... Tail>
void print_rest(T &&head, Tail &&...tail) const {
std::cout << sep << head, print_rest(std::forward<Tail>(tail)...);
}
};
public:
Prints() {}
__Prints operator()(const char *sep = " ", const char *term = "\n") const {
return __Prints(sep, term);
}
template <class T>
void print_vec(const std::vector<T> &vec, const char *sep = " ",
const char *term = "\n") const {
const size_t sz = vec.size();
for (size_t i = 0; i < sz; i++)
std::cout << vec[i] << (i == sz - 1 ? term : sep);
}
};
Prints prints;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
template <typename T> class BIT {
private:
int n;
std::vector<T> vec;
public:
BIT(int n) : n(n), vec(n + 1) {}
// i 番目の要素に a を足す
void add(int i, const T &a) {
for (++i; i <= n; i += i & (-i)) {
vec[i] += a;
}
}
// 区間[0, i)に対するクエリを実行する
T query(int i) const {
T res = 0;
for (; i >= 1; i -= i & (-i)) {
res += vec[i];
}
return res;
}
// 区間[i, j)に対するクエリを実行する
T query(int i, int j) const { return query(j) - query(i); }
size_t size() const noexcept { return n; }
void reset() noexcept {
std::fill(vec.begin(), vec.end(), static_cast<T>(0));
}
};
void solve() {
ll N, Q;
cin >> N >> Q;
Vl C(N);
for (ll i = 0; i < N; i++) {
cin >> C[i];
--C[i];
}
using Tup = tuple<ll, ll, ll>;
vector<Tup> queries(Q);
for (ll i = 0; i < Q; i++) {
ll a, b;
cin >> a >> b;
--a;
queries[i] = {b, a, i}; // 左右逆
}
sort(queries.begin(), queries.end());
BIT<ll> bb(N);
Vl la(N, -1);
ll cur = 0;
Vl ans(N);
for (ll i = 0; i < Q; i++) {
auto [right, left, idx] = queries[i];
while (cur < right) {
if (la[C[cur]] != -1) {
bb.add(la[C[cur]], -1);
}
la[C[cur]] = cur;
bb.add(cur, 1);
++cur;
}
ans[idx] = bb.query(left, right);
}
for (ll i = 0; i < Q; i++) {
prints()(ans[i]);
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
cout << setprecision(18) << fixed;
solve();
cout << flush;
return 0;
} | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
class Prints {
private:
class __Prints {
public:
__Prints(const char *sep, const char *term) : sep(sep), term(term) {}
template <class... Args> void operator()(Args &&...args) const {
print(std::forward<Args>(args)...);
}
private:
const char *sep, *term;
void print() const { std::cout << term; }
void print_rest() const { std::cout << term; }
template <class T, class... Tail>
void print(T &&head, Tail &&...tail) const {
std::cout << head, print_rest(std::forward<Tail>(tail)...);
}
template <class T, class... Tail>
void print_rest(T &&head, Tail &&...tail) const {
std::cout << sep << head, print_rest(std::forward<Tail>(tail)...);
}
};
public:
Prints() {}
__Prints operator()(const char *sep = " ", const char *term = "\n") const {
return __Prints(sep, term);
}
template <class T>
void print_vec(const std::vector<T> &vec, const char *sep = " ",
const char *term = "\n") const {
const size_t sz = vec.size();
for (size_t i = 0; i < sz; i++)
std::cout << vec[i] << (i == sz - 1 ? term : sep);
}
};
Prints prints;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
template <typename T> class BIT {
private:
int n;
std::vector<T> vec;
public:
BIT(int n) : n(n), vec(n + 1) {}
// i 番目の要素に a を足す
void add(int i, const T &a) {
for (++i; i <= n; i += i & (-i)) {
vec[i] += a;
}
}
// 区間[0, i)に対するクエリを実行する
T query(int i) const {
T res = 0;
for (; i >= 1; i -= i & (-i)) {
res += vec[i];
}
return res;
}
// 区間[i, j)に対するクエリを実行する
T query(int i, int j) const { return query(j) - query(i); }
size_t size() const noexcept { return n; }
void reset() noexcept {
std::fill(vec.begin(), vec.end(), static_cast<T>(0));
}
};
void solve() {
ll N, Q;
cin >> N >> Q;
Vl C(N);
for (ll i = 0; i < N; i++) {
cin >> C[i];
--C[i];
}
using Tup = tuple<ll, ll, ll>;
vector<Tup> queries(Q);
for (ll i = 0; i < Q; i++) {
ll a, b;
cin >> a >> b;
--a;
queries[i] = {b, a, i}; // 左右逆
}
sort(queries.begin(), queries.end());
BIT<ll> bb(N);
Vl la(N, -1);
ll cur = 0;
Vl ans(Q);
for (ll i = 0; i < Q; i++) {
auto [right, left, idx] = queries[i];
while (cur < right) {
if (la[C[cur]] != -1) {
bb.add(la[C[cur]], -1);
}
la[C[cur]] = cur;
bb.add(cur, 1);
++cur;
}
ans[idx] = bb.query(left, right);
}
for (ll i = 0; i < Q; i++) {
prints()(ans[i]);
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
cout << setprecision(18) << fixed;
solve();
cout << flush;
return 0;
} | replace | 103 | 104 | 103 | 104 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 500000;
int pre[N + 5];
template <int M, int SZ> struct Persistable_Segment_Tree {
int tot, p, k, L, R;
int rt[M + 5], lc[SZ + 5], rc[SZ + 5], cntv[SZ + 5];
void init() { tot = rt[0] = lc[0] = rc[0] = cntv[0] = 0; }
int update(int pre, int l, int r, int k) {
int now = ++tot;
if (l == r) {
cntv[now] = cntv[pre] + k;
} else {
int m = (l + r) >> 1;
if (p <= m) {
lc[now] = update(lc[pre], l, m, k);
rc[now] = rc[pre];
} else {
rc[now] = update(rc[pre], m + 1, r, k);
lc[now] = lc[pre];
}
cntv[now] = cntv[lc[now]] + cntv[rc[now]];
}
return now;
}
void query(int o, int l, int r) {
if (L <= l && r <= R) {
k += cntv[o];
} else {
int m = (l + r) >> 1;
if (L <= m)
query(lc[o], l, m);
if (R > m)
query(rc[o], m + 1, r);
}
}
};
Persistable_Segment_Tree<N, N * 20> psegt;
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
int rt = psegt.rt[i - 1];
if (pre[x]) {
psegt.p = pre[x];
rt = psegt.update(rt, 1, n, -1);
}
pre[x] = i;
psegt.p = i;
rt = psegt.update(rt, 1, n, 1);
psegt.rt[i] = rt;
}
for (int i = 1; i <= q; ++i) {
int l, r;
scanf("%d %d", &l, &r);
psegt.L = l;
psegt.R = r;
psegt.k = 0;
psegt.query(psegt.rt[r], 1, n);
printf("%d\n", psegt.k);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 500000;
int pre[N + 5];
template <int M, int SZ> struct Persistable_Segment_Tree {
int tot, p, k, L, R;
int rt[M + 5], lc[SZ + 5], rc[SZ + 5], cntv[SZ + 5];
void init() { tot = rt[0] = lc[0] = rc[0] = cntv[0] = 0; }
int update(int pre, int l, int r, int k) {
int now = ++tot;
if (l == r) {
cntv[now] = cntv[pre] + k;
} else {
int m = (l + r) >> 1;
if (p <= m) {
lc[now] = update(lc[pre], l, m, k);
rc[now] = rc[pre];
} else {
rc[now] = update(rc[pre], m + 1, r, k);
lc[now] = lc[pre];
}
cntv[now] = cntv[lc[now]] + cntv[rc[now]];
}
return now;
}
void query(int o, int l, int r) {
if (L <= l && r <= R) {
k += cntv[o];
} else {
int m = (l + r) >> 1;
if (L <= m)
query(lc[o], l, m);
if (R > m)
query(rc[o], m + 1, r);
}
}
};
Persistable_Segment_Tree<N, N * 40> psegt;
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
int rt = psegt.rt[i - 1];
if (pre[x]) {
psegt.p = pre[x];
rt = psegt.update(rt, 1, n, -1);
}
pre[x] = i;
psegt.p = i;
rt = psegt.update(rt, 1, n, 1);
psegt.rt[i] = rt;
}
for (int i = 1; i <= q; ++i) {
int l, r;
scanf("%d %d", &l, &r);
psegt.L = l;
psegt.R = r;
psegt.k = 0;
psegt.query(psegt.rt[r], 1, n);
printf("%d\n", psegt.k);
}
return 0;
} | replace | 41 | 42 | 41 | 42 | -11 | |
p02599 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define ll long long
#define MAX 500000
#define MAX1 1148576
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007
int c[MAX + 5], tree[MAX1 + 5], last[MAX + 5];
struct node {
int l, r, id;
} query[MAX + 5];
int ans[MAX + 5];
bool compare(node a, node b) { return a.r <= b.r; }
void update(int id, int l, int r, int pos, int val) {
if (l == r) {
tree[id] += val;
return;
}
int lt = id << 1, rt = lt | 1, mid = (l + r) >> 1;
if (pos <= mid) {
update(lt, l, mid, pos, val);
} else {
update(rt, mid + 1, r, pos, val);
}
tree[id] = tree[lt] + tree[rt];
}
int get(int id, int l, int r, int rl, int rr) {
if (l > r or r < rl or l > rr) {
return 0;
}
if (l >= rl and r <= rr) {
return tree[id];
}
int lt = id << 1, rt = lt | 1, mid = (l + r) >> 1;
return get(lt, l, mid, rl, rr) + get(rt, mid + 1, r, rl, rr);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q, i, j, l, r;
cin >> n >> q;
for (i = 1; i <= n; ++i) {
cin >> c[i];
}
for (i = 0; i < q; ++i) {
cin >> l >> r;
query[i] = {l, r, i};
}
sort(query, query + q, compare);
for (j = 0, i = 1; i <= n; ++i) {
if (last[c[i]]) {
update(1, 1, n, last[c[i]], -1);
}
last[c[i]] = i;
update(1, 1, n, last[c[i]], 1);
while (j < q and query[j].r == i) {
ans[query[j].id] = get(1, 1, n, query[j].l, query[j].r);
++j;
}
}
for (i = 0; i < q; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define ll long long
#define MAX 500000
#define MAX1 1148576
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007
int c[MAX + 5], tree[MAX1 + 5], last[MAX + 5];
struct node {
int l, r, id;
} query[MAX + 5];
int ans[MAX + 5];
bool compare(node a, node b) { return a.r < b.r; }
void update(int id, int l, int r, int pos, int val) {
if (l == r) {
tree[id] += val;
return;
}
int lt = id << 1, rt = lt | 1, mid = (l + r) >> 1;
if (pos <= mid) {
update(lt, l, mid, pos, val);
} else {
update(rt, mid + 1, r, pos, val);
}
tree[id] = tree[lt] + tree[rt];
}
int get(int id, int l, int r, int rl, int rr) {
if (l > r or r < rl or l > rr) {
return 0;
}
if (l >= rl and r <= rr) {
return tree[id];
}
int lt = id << 1, rt = lt | 1, mid = (l + r) >> 1;
return get(lt, l, mid, rl, rr) + get(rt, mid + 1, r, rl, rr);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q, i, j, l, r;
cin >> n >> q;
for (i = 1; i <= n; ++i) {
cin >> c[i];
}
for (i = 0; i < q; ++i) {
cin >> l >> r;
query[i] = {l, r, i};
}
sort(query, query + q, compare);
for (j = 0, i = 1; i <= n; ++i) {
if (last[c[i]]) {
update(1, 1, n, last[c[i]], -1);
}
last[c[i]] = i;
update(1, 1, n, last[c[i]], 1);
while (j < q and query[j].r == i) {
ans[query[j].id] = get(1, 1, n, query[j].l, query[j].r);
++j;
}
}
for (i = 0; i < q; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)
template <typename T> struct fenwick_tree {
int n;
vector<T> d;
fenwick_tree(int n = 0) : n(n), d(n + 1) {}
void add(int i, T x) {
i++;
while (i <= n) {
d[i] += x;
i += i & -i;
}
}
T sum(int i) {
i++;
T x = 0;
while (i > 0) {
x += d[i];
i -= i & -i;
}
return x;
}
};
int main() {
ll N, Q, l, r, idx = 0;
cin >> N >> Q;
vector<ll> c(N), good(N, -1), ans(N);
REP(i, N) {
cin >> c[i];
c[i]--;
}
vector<tuple<ll, ll, ll>> query(Q);
REP(i, Q) {
cin >> l >> r;
query[i] = {r - 1, l - 1, i};
}
sort(query.begin(), query.end());
fenwick_tree<ll> fw(N);
REP(i, N) {
if (good[c[i]] != -1)
fw.add(good[c[i]], -1);
good[c[i]] = i;
fw.add(i, 1);
while (idx != Q && get<0>(query[idx]) == i) {
ans[get<2>(query[idx])] =
fw.sum(get<0>(query[idx])) - fw.sum(get<1>(query[idx]) - 1);
idx++;
}
}
REP(i, Q) cout << ans[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)
template <typename T> struct fenwick_tree {
int n;
vector<T> d;
fenwick_tree(int n = 0) : n(n), d(n + 1) {}
void add(int i, T x) {
i++;
while (i <= n) {
d[i] += x;
i += i & -i;
}
}
T sum(int i) {
i++;
T x = 0;
while (i > 0) {
x += d[i];
i -= i & -i;
}
return x;
}
};
int main() {
ll N, Q, l, r, idx = 0;
cin >> N >> Q;
vector<ll> c(N), good(N, -1), ans(Q);
REP(i, N) {
cin >> c[i];
c[i]--;
}
vector<tuple<ll, ll, ll>> query(Q);
REP(i, Q) {
cin >> l >> r;
query[i] = {r - 1, l - 1, i};
}
sort(query.begin(), query.end());
fenwick_tree<ll> fw(N);
REP(i, N) {
if (good[c[i]] != -1)
fw.add(good[c[i]], -1);
good[c[i]] = i;
fw.add(i, 1);
while (idx != Q && get<0>(query[idx]) == i) {
ans[get<2>(query[idx])] =
fw.sum(get<0>(query[idx])) - fw.sum(get<1>(query[idx]) - 1);
idx++;
}
}
REP(i, Q) cout << ans[i] << endl;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02599 | C++ | Time Limit Exceeded |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << endl; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;
template <typename T> struct BIT {
int N;
vector<T> dat;
// [0, N], 1-indexing!!!
explicit BIT(int n) : N(n), dat(N + 1, 0) {}
T sum(int i) {
T s = 0;
while (i > 0) {
s += dat[i];
i -= i & -i; // i = i & (i-1)
}
return s;
}
void add(int i, T x) {
while (i <= N) {
dat[i] += x;
i += i & -i;
}
}
// min_x {x | v1 + v2 + ⋯ + vx ≧ w}
// Assuming v_q >= 0
int lower_bound(T w) {
if (w <= 0)
return 0;
int x = 0;
T k = 1;
while (k * 2 <= N)
k <<= 1;
for (; k > 0; k /= 2) {
if (x + k <= N && dat[x + k] < w) {
w -= dat[x + k];
x += k;
}
}
return x + 1;
}
};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, Q;
cin >> N >> Q;
vll c(N);
REP(i, N) cin >> c[i];
vector<pair<pair<int, int>, int>> query;
REP(i, Q) {
int l, r;
cin >> l >> r;
query.pb({{r, l}, i});
}
sort(ALL(query));
vector<ll> last(N, -1);
BIT<ll> bit(N);
int r_prev = 1;
vector<pair<int, ll>> ans;
REP(i, Q) {
auto p = query[i];
int l = p.fi.se, r = p.fi.fi;
for (int j = r_prev; j <= r; ++j) {
if (last[c[j - 1]] > -1)
bit.add(last[c[j - 1]], -1);
last[c[j - 1]] = j;
bit.add(j, 1);
}
r_prev = r;
ans.eb(p.se, bit.sum(r) - bit.sum(l - 1));
}
sort(ALL(ans));
REP(i, ans.size()) { print(ans[i].se); }
}
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << endl; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;
template <typename T> struct BIT {
int N;
vector<T> dat;
// [0, N], 1-indexing!!!
explicit BIT(int n) : N(n), dat(N + 1, 0) {}
T sum(int i) {
T s = 0;
while (i > 0) {
s += dat[i];
i -= i & -i; // i = i & (i-1)
}
return s;
}
void add(int i, T x) {
while (i <= N) {
dat[i] += x;
i += i & -i;
}
}
// min_x {x | v1 + v2 + ⋯ + vx ≧ w}
// Assuming v_q >= 0
int lower_bound(T w) {
if (w <= 0)
return 0;
int x = 0;
T k = 1;
while (k * 2 <= N)
k <<= 1;
for (; k > 0; k /= 2) {
if (x + k <= N && dat[x + k] < w) {
w -= dat[x + k];
x += k;
}
}
return x + 1;
}
};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, Q;
cin >> N >> Q;
vll c(N);
REP(i, N) cin >> c[i];
vector<pair<pair<int, int>, int>> query;
REP(i, Q) {
int l, r;
cin >> l >> r;
query.pb({{r, l}, i});
}
sort(ALL(query));
vector<ll> last(N, -1);
BIT<ll> bit(N);
int r_prev = 1;
vector<pair<int, ll>> ans;
REP(i, Q) {
auto p = query[i];
int l = p.fi.se, r = p.fi.fi;
for (int j = r_prev; j <= r; ++j) {
if (last[c[j - 1]] > 0)
bit.add(last[c[j - 1]], -1);
last[c[j - 1]] = j;
bit.add(j, 1);
}
r_prev = r;
ans.eb(p.se, bit.sum(r) - bit.sum(l - 1));
}
sort(ALL(ans));
REP(i, ans.size()) { print(ans[i].se); }
}
| replace | 120 | 121 | 120 | 121 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * (int)1e4 + 100;
int n, a[maxn], b[maxn], t[maxn * 40], lt[maxn * 40], rt[maxn * 40],
tVal[maxn * 40], tot;
int lst[maxn]; // 记录离散化后数组的上次出现位置
int q;
void init() {
tot = 0;
memset(lst, -1, sizeof(lst));
}
int build(int l, int r) {
int node = ++tot;
tVal[node] = 0;
int mid = (l + r) >> 1;
if (l < r) {
lt[node] = build(l, mid);
rt[node] = build(mid + 1, r);
}
return node;
}
int update(int l, int r, int par, int p, int val) {
int node = ++tot;
lt[node] = lt[par];
rt[node] = rt[par];
tVal[node] = tVal[par] + val;
int mid = (l + r) >> 1;
if (l < r) {
if (p <= mid)
lt[node] = update(l, mid, lt[par], p, val);
else
rt[node] = update(mid + 1, r, rt[par], p, val);
}
return node;
}
int query(int l, int r, int p, int node) {
if (l == r)
return tVal[node];
int mid = (l + r) >> 1;
if (p <= mid)
return (query(l, mid, p, lt[node]) + tVal[rt[node]]);
else
return query(mid + 1, r, p, rt[node]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
init();
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + 1 + n);
int len = unique(b + 1, b + 1 + n) - b;
for (int i = 1; i <= n; ++i)
a[i] = lower_bound(b + 1, b + 1 + len, a[i]) - b;
t[0] = build(1, n);
for (int i = 1; i <= n; ++i) {
if (lst[a[i]] == -1)
t[i] = update(1, n, t[i - 1], i, 1);
else {
int temp = update(1, n, t[i - 1], lst[a[i]], -1);
t[i] = update(1, n, temp, i, 1);
}
lst[a[i]] = i;
}
while (q--) {
int l, r;
cin >> l >> r;
cout << query(1, n, l, t[r]) << '\n';
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * (int)1e5 + 100;
int n, a[maxn], b[maxn], t[maxn * 70], lt[maxn * 70], rt[maxn * 70],
tVal[maxn * 70], tot;
int lst[maxn]; // 记录离散化后数组的上次出现位置
int q;
void init() {
tot = 0;
memset(lst, -1, sizeof(lst));
}
int build(int l, int r) {
int node = ++tot;
tVal[node] = 0;
int mid = (l + r) >> 1;
if (l < r) {
lt[node] = build(l, mid);
rt[node] = build(mid + 1, r);
}
return node;
}
int update(int l, int r, int par, int p, int val) {
int node = ++tot;
lt[node] = lt[par];
rt[node] = rt[par];
tVal[node] = tVal[par] + val;
int mid = (l + r) >> 1;
if (l < r) {
if (p <= mid)
lt[node] = update(l, mid, lt[par], p, val);
else
rt[node] = update(mid + 1, r, rt[par], p, val);
}
return node;
}
int query(int l, int r, int p, int node) {
if (l == r)
return tVal[node];
int mid = (l + r) >> 1;
if (p <= mid)
return (query(l, mid, p, lt[node]) + tVal[rt[node]]);
else
return query(mid + 1, r, p, rt[node]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
init();
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + 1 + n);
int len = unique(b + 1, b + 1 + n) - b;
for (int i = 1; i <= n; ++i)
a[i] = lower_bound(b + 1, b + 1 + len, a[i]) - b;
t[0] = build(1, n);
for (int i = 1; i <= n; ++i) {
if (lst[a[i]] == -1)
t[i] = update(1, n, t[i - 1], i, 1);
else {
int temp = update(1, n, t[i - 1], lst[a[i]], -1);
t[i] = update(1, n, temp, i, 1);
}
lst[a[i]] = i;
}
while (q--) {
int l, r;
cin >> l >> r;
cout << query(1, n, l, t[r]) << '\n';
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| replace | 4 | 7 | 4 | 7 | 0 | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int BLOCK = 707;
int c[500005], ans[500005], res, cnt[500005];
struct dat {
int l, r, id;
bool operator<(const dat &T) const {
if (l / BLOCK != T.l / BLOCK)
return l / BLOCK < T.l / BLOCK;
return r / BLOCK < T.r / BLOCK;
}
} a[500005];
void remove(int id) {
cnt[c[id]]--;
if (cnt[c[id]] == 0)
res--;
}
void add(int id) {
cnt[c[id]]++;
if (cnt[c[id]] == 1)
res++;
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++)
scanf("%d", &c[i]);
for (int i = 0; i < q; i++) {
scanf("%d%d", &a[i].l, &a[i].r);
a[i].l--;
a[i].r--;
a[i].id = i;
}
sort(a, a + q);
int l = 0;
int r = -1;
res = 0;
for (int i = 0; i < q; i++) {
while (l < a[i].l)
remove(l++);
while (l > a[i].l)
add(--l);
while (r < a[i].r)
add(++r);
while (r > a[i].r)
remove(r--);
ans[a[i].id] = res;
}
for (int i = 0; i < q; i++)
printf("%d\n", ans[i]);
}
| #include <bits/stdc++.h>
using namespace std;
const int BLOCK = 707;
int c[500005], ans[500005], res, cnt[500005];
struct dat {
int l, r, id;
bool operator<(const dat &T) const {
if (l / BLOCK != T.l / BLOCK)
return l / BLOCK < T.l / BLOCK;
return r < T.r;
}
} a[500005];
void remove(int id) {
cnt[c[id]]--;
if (cnt[c[id]] == 0)
res--;
}
void add(int id) {
cnt[c[id]]++;
if (cnt[c[id]] == 1)
res++;
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++)
scanf("%d", &c[i]);
for (int i = 0; i < q; i++) {
scanf("%d%d", &a[i].l, &a[i].r);
a[i].l--;
a[i].r--;
a[i].id = i;
}
sort(a, a + q);
int l = 0;
int r = -1;
res = 0;
for (int i = 0; i < q; i++) {
while (l < a[i].l)
remove(l++);
while (l > a[i].l)
add(--l);
while (r < a[i].r)
add(++r);
while (r > a[i].r)
remove(r--);
ans[a[i].id] = res;
}
for (int i = 0; i < q; i++)
printf("%d\n", ans[i]);
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename T> class BIT {
vector<T> tree_;
public:
BIT(int n) : tree_(n, 0) {}
void Add(int i, T x) {
for (i++; i <= tree_.size(); i += i & -i) {
tree_[i - 1] += x;
}
}
T Sum(int s) {
T ans = 0;
for (s++; s > 0; s -= s & -s) {
ans += tree_[s - 1];
}
return ans;
}
T Sum(int l, int r) { return Sum(r) - Sum(l - 1); }
};
int main(int argc, const char *argv[]) {
int n, q;
cin >> n >> q;
vector<int> vc(n);
for (int i = 0; i < n; ++i) {
cin >> vc[i];
vc[i]--;
}
vector<array<int, 3>> vq(n);
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
vq[i][0] = r - 1;
vq[i][1] = l - 1;
vq[i][2] = i;
}
sort(vq.begin(), vq.end());
BIT<int> bit(n);
vector<int> vp(n, -1), ans(q);
int prev = 0;
for (auto &q : vq) {
int l, r, idx;
r = q[0];
l = q[1];
idx = q[2];
for (int i = prev; i <= r; ++i) {
int c = vc[i];
if (vp[c] < i) {
if (vp[c] != -1) {
bit.Add(vp[c], -1);
}
bit.Add(i, 1);
vp[c] = i;
}
ans[idx] = bit.Sum(l, r);
}
prev = r;
}
for (int i = 0; i < ans.size(); ++i) {
cout << ans[i] << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> class BIT {
vector<T> tree_;
public:
BIT(int n) : tree_(n, 0) {}
void Add(int i, T x) {
for (i++; i <= tree_.size(); i += i & -i) {
tree_[i - 1] += x;
}
}
T Sum(int s) {
T ans = 0;
for (s++; s > 0; s -= s & -s) {
ans += tree_[s - 1];
}
return ans;
}
T Sum(int l, int r) { return Sum(r) - Sum(l - 1); }
};
int main(int argc, const char *argv[]) {
int n, q;
cin >> n >> q;
vector<int> vc(n);
for (int i = 0; i < n; ++i) {
cin >> vc[i];
vc[i]--;
}
vector<array<int, 3>> vq(q);
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
vq[i][0] = r - 1;
vq[i][1] = l - 1;
vq[i][2] = i;
}
sort(vq.begin(), vq.end());
BIT<int> bit(n);
vector<int> vp(n, -1), ans(q);
int prev = 0;
for (auto &q : vq) {
int l, r, idx;
r = q[0];
l = q[1];
idx = q[2];
for (int i = prev; i <= r; ++i) {
int c = vc[i];
if (vp[c] < i) {
if (vp[c] != -1) {
bit.Add(vp[c], -1);
}
bit.Add(i, 1);
vp[c] = i;
}
ans[idx] = bit.Sum(l, r);
}
prev = r;
}
for (int i = 0; i < ans.size(); ++i) {
cout << ans[i] << '\n';
}
return 0;
} | replace | 37 | 38 | 37 | 38 | 0 | |
p02599 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define Per(i, sta, n) for (int i = n - 1; i >= sta; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
struct Mo {
using F = function<void(int)>;
vector<int> ls, rs, ord;
int n, width, nl, nr, ptr; // widthは分割するバレットの幅
F expandL, expandR;
F shrinkL, shrinkR;
Mo(int n, int width, F expandL, F expandR, F shrinkL, F shrinkR)
: n(n), width(width), nl(0), nr(0), ptr(0), expandL(expandL),
expandR(expandR), shrinkL(shrinkL), shrinkR(shrinkR) {}
Mo(int n, int width, F expand, F shrink) {
*this = Mo(n, width, expand, expand, shrink, shrink);
}
void add(int l, int r) { // 区間[l,r)
ls.emplace_back(l);
rs.emplace_back(r);
}
void build() {
ord.resize(ls.size());
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int a, int b) {
if (ls[a] / width != ls[b] / width)
return ls[a] < ls[b];
if (rs[a] == rs[b])
return ls[a] < ls[b];
return bool((rs[a] < rs[b]) ^ ((ls[a] / width) & 1));
});
}
int process() {
if (ptr == (int)ord.size())
return -1;
const int idx = ord[ptr++];
while (nl > ls[idx])
expandL(--nl);
while (nr < rs[idx])
expandR(nr++);
while (nl < ls[idx])
shrinkL(nl++);
while (nr > rs[idx])
shrinkR(--nr);
return idx;
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<int> c(n), cnt(n), ans(q);
rep(i, n) {
cin >> c[i];
c[i]--;
}
int num = 0;
auto expand = [&](int k) {
cnt[c[k]] += 1;
if (cnt[c[k]] == 1)
num += 1;
};
auto shrink = [&](int k) {
cnt[c[k]] -= 1;
if (cnt[c[k]] == 0)
num -= 1;
};
Mo mo(n, 1000, expand, shrink);
rep(i, q) {
int l, r;
cin >> l >> r;
l--;
mo.add(l, r);
}
mo.build();
rep(i, q) {
int k = mo.process();
ans[k] = num;
}
rep(i, q) { cout << ans[i] << "\n"; }
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(50);
solve();
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define Per(i, sta, n) for (int i = n - 1; i >= sta; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
struct Mo {
using F = function<void(int)>;
vector<int> ls, rs, ord;
int n, width, nl, nr, ptr; // widthは分割するバレットの幅
F expandL, expandR;
F shrinkL, shrinkR;
Mo(int n, int width, F expandL, F expandR, F shrinkL, F shrinkR)
: n(n), width(width), nl(0), nr(0), ptr(0), expandL(expandL),
expandR(expandR), shrinkL(shrinkL), shrinkR(shrinkR) {}
Mo(int n, int width, F expand, F shrink) {
*this = Mo(n, width, expand, expand, shrink, shrink);
}
void add(int l, int r) { // 区間[l,r)
ls.emplace_back(l);
rs.emplace_back(r);
}
void build() {
ord.resize(ls.size());
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int a, int b) {
if (ls[a] / width != ls[b] / width)
return ls[a] < ls[b];
if (rs[a] == rs[b])
return ls[a] < ls[b];
return bool((rs[a] < rs[b]) ^ ((ls[a] / width) & 1));
});
}
int process() {
if (ptr == (int)ord.size())
return -1;
const int idx = ord[ptr++];
while (nl > ls[idx])
expandL(--nl);
while (nr < rs[idx])
expandR(nr++);
while (nl < ls[idx])
shrinkL(nl++);
while (nr > rs[idx])
shrinkR(--nr);
return idx;
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<int> c(n), cnt(n), ans(q);
rep(i, n) {
cin >> c[i];
c[i]--;
}
int num = 0;
auto expand = [&](int k) { num += cnt[c[k]]++ == 0; };
auto shrink = [&](int k) { num -= --cnt[c[k]] == 0; };
Mo mo(n, 1000, expand, shrink);
rep(i, q) {
int l, r;
cin >> l >> r;
l--;
mo.add(l, r);
}
mo.build();
rep(i, q) {
int k = mo.process();
ans[k] = num;
}
rep(i, q) { cout << ans[i] << "\n"; }
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(50);
solve();
} | replace | 100 | 110 | 100 | 102 | TLE | |
p02599 | C++ | Time Limit Exceeded | // Author : Prakhar Asaiya
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define REPN(i, a, b) for (int i = a; i <= b; ++i)
#define REPV(i, a, b) for (int i = a; i >= b; --i)
#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define ll long long
#define INF 100000
#define ff first
#define ss second
const int M = 1e9 + 7;
const int N = 500005;
struct query {
int l, r, i;
};
const int BLK = 700;
query Q[N];
int A[N], ans[N], freq[N];
int cnt = 0;
bool cmp(query a, query b) {
if (a.l / BLK != b.l / BLK)
return a.l / BLK < b.l / BLK;
return a.r < b.r;
}
void add(int pos) {
++freq[A[pos]];
if (freq[A[pos]] == 1)
++cnt;
}
void remove(int pos) {
--freq[A[pos]];
if (freq[A[pos]] == 0)
--cnt;
}
void solve() {
int n, q;
cin >> n >> q;
REP(i, 0, n)
cin >> A[i];
REP(i, 0, q) {
cin >> Q[i].l >> Q[i].r;
--Q[i].l, --Q[i].r;
Q[i].i = i;
}
sort(Q, Q + q, cmp);
int ml = 0, mr = -1;
REP(i, 0, q) {
int l = Q[i].l;
int r = Q[i].r;
while (ml > l) {
--ml;
add(ml);
}
while (mr < r) {
++mr;
add(mr);
}
while (ml < l) {
remove(ml);
++ml;
}
while (mr > r) {
remove(mr);
--mr;
}
ans[Q[i].i] = cnt;
}
REP(i, 0, q) { cout << ans[i] << "\n"; }
}
int main() { /*
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#*/
ios_base::sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
| // Author : Prakhar Asaiya
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define REPN(i, a, b) for (int i = a; i <= b; ++i)
#define REPV(i, a, b) for (int i = a; i >= b; --i)
#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define ll long long
#define INF 100000
#define ff first
#define ss second
const int M = 1e9 + 7;
const int N = 500005;
struct query {
int l, r, i;
};
const int BLK = 800;
query Q[N];
int A[N], ans[N], freq[N];
int cnt = 0;
bool cmp(query a, query b) {
if (a.l / BLK != b.l / BLK)
return a.l / BLK < b.l / BLK;
return a.r < b.r;
}
void add(int pos) {
++freq[A[pos]];
if (freq[A[pos]] == 1)
++cnt;
}
void remove(int pos) {
--freq[A[pos]];
if (freq[A[pos]] == 0)
--cnt;
}
void solve() {
int n, q;
cin >> n >> q;
REP(i, 0, n)
cin >> A[i];
REP(i, 0, q) {
cin >> Q[i].l >> Q[i].r;
--Q[i].l, --Q[i].r;
Q[i].i = i;
}
sort(Q, Q + q, cmp);
int ml = 0, mr = -1;
REP(i, 0, q) {
int l = Q[i].l;
int r = Q[i].r;
while (ml > l) {
--ml;
add(ml);
}
while (mr < r) {
++mr;
add(mr);
}
while (ml < l) {
remove(ml);
++ml;
}
while (mr > r) {
remove(mr);
--mr;
}
ans[Q[i].i] = cnt;
}
REP(i, 0, q) { cout << ans[i] << "\n"; }
}
int main() { /*
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#*/
ios_base::sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
| replace | 20 | 21 | 20 | 21 | TLE | |
p02599 | C++ | Runtime Error | // C++ code to find number of distinct numbers
// in a subarray
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
// structure to store queries
struct Query {
int l, r, idx;
};
// cmp function to sort queries according to r
bool cmp(Query x, Query y) { return x.r < y.r; }
// updating the bit array
void update(int idx, int val, int bit[], int n) {
for (; idx <= n; idx += idx & -idx)
bit[idx] += val;
}
// querying the bit array
int query(int idx, int bit[], int n) {
int sum = 0;
for (; idx > 0; idx -= idx & -idx)
sum += bit[idx];
return sum;
}
void answeringQueries(int arr[], int n, Query queries[], int q) {
// initialising bit array
int bit[n + 1];
memset(bit, 0, sizeof(bit));
// holds the rightmost index of any number
// as numbers of a[i] are less than or equal to 10^6
int last_visit[MAX];
memset(last_visit, -1, sizeof(last_visit));
// answer for each query
int ans[q];
int query_counter = 0;
for (int i = 0; i < n; i++) {
// If last visit is not -1 update -1 at the
// idx equal to last_visit[arr[i]]
if (last_visit[arr[i]] != -1)
update(last_visit[arr[i]] + 1, -1, bit, n);
// Setting last_visit[arr[i]] as i and updating
// the bit array accordingly
last_visit[arr[i]] = i;
update(i + 1, 1, bit, n);
// If i is equal to r of any query store answer
// for that query in ans[]
while (query_counter < q && queries[query_counter].r == i) {
ans[queries[query_counter].idx] =
query(queries[query_counter].r + 1, bit, n) -
query(queries[query_counter].l, bit, n);
query_counter++;
}
}
// print answer for each query
for (int i = 0; i < q; i++)
cout << ans[i] << endl;
}
// driver code
int main() {
int n, q;
cin >> n >> q;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int ll, rr;
Query queries[q];
for (int i = 0; i < q; i++) {
cin >> ll >> rr;
ll--;
rr--;
queries[i].l = ll;
queries[i].r = rr;
queries[i].idx = i;
}
sort(queries, queries + q, cmp);
answeringQueries(a, n, queries, q);
return 0;
}
| // C++ code to find number of distinct numbers
// in a subarray
#include <bits/stdc++.h>
using namespace std;
const int MAX = 500005;
// structure to store queries
struct Query {
int l, r, idx;
};
// cmp function to sort queries according to r
bool cmp(Query x, Query y) { return x.r < y.r; }
// updating the bit array
void update(int idx, int val, int bit[], int n) {
for (; idx <= n; idx += idx & -idx)
bit[idx] += val;
}
// querying the bit array
int query(int idx, int bit[], int n) {
int sum = 0;
for (; idx > 0; idx -= idx & -idx)
sum += bit[idx];
return sum;
}
void answeringQueries(int arr[], int n, Query queries[], int q) {
// initialising bit array
int bit[n + 1];
memset(bit, 0, sizeof(bit));
// holds the rightmost index of any number
// as numbers of a[i] are less than or equal to 10^6
int last_visit[MAX];
memset(last_visit, -1, sizeof(last_visit));
// answer for each query
int ans[q];
int query_counter = 0;
for (int i = 0; i < n; i++) {
// If last visit is not -1 update -1 at the
// idx equal to last_visit[arr[i]]
if (last_visit[arr[i]] != -1)
update(last_visit[arr[i]] + 1, -1, bit, n);
// Setting last_visit[arr[i]] as i and updating
// the bit array accordingly
last_visit[arr[i]] = i;
update(i + 1, 1, bit, n);
// If i is equal to r of any query store answer
// for that query in ans[]
while (query_counter < q && queries[query_counter].r == i) {
ans[queries[query_counter].idx] =
query(queries[query_counter].r + 1, bit, n) -
query(queries[query_counter].l, bit, n);
query_counter++;
}
}
// print answer for each query
for (int i = 0; i < q; i++)
cout << ans[i] << endl;
}
// driver code
int main() {
int n, q;
cin >> n >> q;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int ll, rr;
Query queries[q];
for (int i = 0; i < q; i++) {
cin >> ll >> rr;
ll--;
rr--;
queries[i].l = ll;
queries[i].r = rr;
queries[i].idx = i;
}
sort(queries, queries + q, cmp);
answeringQueries(a, n, queries, q);
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pf printf
#define PF(a) printf("%d\n", (a))
#define PF2(a, b) printf("%d %d\n", (a), (b))
#define PF3(a, b, c) printf("%d %d %d\n", (a), (b), (c))
#define PFL(a) printf("%lld\n", (a))
#define PFL2(a, b) printf("%lld %lld\n", (a), (b))
#define PFL3(a, b, c) printf("%lld %lld %lld\n", (a), (b), (c))
#define get(a) cin >> a
#define sf scanf
#define SF(a) scanf("%d", &a)
#define SF2(a, b) scanf("%d %d", &a, &b)
#define SF3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define SFL(a) scanf("%lld", &a)
#define SFL2(a, b) scanf("%lld %lld", &a, &b)
#define SFL3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define gl(a) getline(cin, (a))
#define gc() getchar()
#define pb push_back
#define m_p make_pair
#define pc() printf("Case %d: ", tt++)
#define tc() cout << "Case " << tt++ << ": "
#define SZ(a) (int)(a).size()
#define all(a) a.begin(), a.end()
#define FF first
#define SS second
#define MAX 2134567891
#define MOD 1000000007
#define MM 100005
#define PI 2 * acos(0.0)
#define cond(n, m) (xx >= 0 && xx < (n) && yy >= 0 && yy < (m))
#define mem(a) memset((a), 0, sizeof(a))
#define SET(a) memset((a), -1, sizeof(a))
#define output freopen("output.txt", "w", stdout);
#define input freopen("input.txt", "r", stdin);
#define I_O \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define rep(a) for (int i = 0; i < (a); i++)
#define FOR(a, b) for (int i = (a); i < (b); i++)
#define REP(a) for (int j = 0; j < (a); j++)
#define rev(a) for (int i = (a); i >= 0; i--)
#define fr(i, n) for (i = 0; i < n; i++)
#define fr1(i, n, m) for (i = n; i < m; i++)
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue<int> PQ;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
/*
//FUNCTION//
ll bigmod(ll a, ll b, ll c)
{
if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=x*x%c;
if(b%2==1)x=x*a%c;return x;
}
ll poww(ll a, ll b)
{
if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=x*a;return x;
}
ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}
int pr = 10000000;
vi primelist;
bool a[MM*100];
void seive( )
{
int i,j,k=sqrt(pr);
a[1]=1;
primelist.pb(2);
for(i=4;i<=pr;i+=2)a[i]=1;
for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}
ll fact_divs( ll n, ll p)
{
ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}
//*/
const int M = MM * 5;
int a[M], root[M];
int avail;
struct node {
int l, r, val;
node() { l = r = val = 0; }
} sum[M * 35];
int update(int PreNode, int l, int r, int L, int val) {
int NewNode = ++avail;
if (l == r) {
sum[NewNode].val = val;
/// sum[NewNode].val = sum[PreNode].val + val;
return NewNode;
}
int mid = (l + r) / 2;
if (L <= mid) {
sum[NewNode].r = sum[PreNode].r;
sum[NewNode].l = update(sum[PreNode].l, l, mid, L, val);
} else {
sum[NewNode].l = sum[PreNode].l;
sum[NewNode].r = update(sum[PreNode].r, mid + 1, r, L, val);
}
sum[NewNode].val = sum[sum[NewNode].l].val + sum[sum[NewNode].r].val;
return NewNode;
}
ll query(int n, int l, int r, int L, int R) {
if (l > R || r < L)
return 0;
if (l >= L && r <= R)
return sum[n].val;
int mid = (l + r) / 2;
int tot = query(sum[n].l, l, mid, L, R) + query(sum[n].r, mid + 1, r, L, R);
return tot;
}
int idx[M];
int main() {
I_O;
int n, m;
cin >> n >> m;
rep(n) cin >> a[i + 1];
for (int i = 1; i <= n; i++) {
if (idx[a[i]]) {
root[i] = update(root[i - 1], 1, n, idx[a[i]], 0);
root[i] = update(root[i], 1, n, i, 1);
} else {
root[i] = update(root[i - 1], 1, n, i, 1);
}
idx[a[i]] = i;
}
rep(m) {
int l, r;
cin >> l >> r;
cout << query(root[r], 1, n, l, r) << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pf printf
#define PF(a) printf("%d\n", (a))
#define PF2(a, b) printf("%d %d\n", (a), (b))
#define PF3(a, b, c) printf("%d %d %d\n", (a), (b), (c))
#define PFL(a) printf("%lld\n", (a))
#define PFL2(a, b) printf("%lld %lld\n", (a), (b))
#define PFL3(a, b, c) printf("%lld %lld %lld\n", (a), (b), (c))
#define get(a) cin >> a
#define sf scanf
#define SF(a) scanf("%d", &a)
#define SF2(a, b) scanf("%d %d", &a, &b)
#define SF3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define SFL(a) scanf("%lld", &a)
#define SFL2(a, b) scanf("%lld %lld", &a, &b)
#define SFL3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define gl(a) getline(cin, (a))
#define gc() getchar()
#define pb push_back
#define m_p make_pair
#define pc() printf("Case %d: ", tt++)
#define tc() cout << "Case " << tt++ << ": "
#define SZ(a) (int)(a).size()
#define all(a) a.begin(), a.end()
#define FF first
#define SS second
#define MAX 2134567891
#define MOD 1000000007
#define MM 100005
#define PI 2 * acos(0.0)
#define cond(n, m) (xx >= 0 && xx < (n) && yy >= 0 && yy < (m))
#define mem(a) memset((a), 0, sizeof(a))
#define SET(a) memset((a), -1, sizeof(a))
#define output freopen("output.txt", "w", stdout);
#define input freopen("input.txt", "r", stdin);
#define I_O \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define rep(a) for (int i = 0; i < (a); i++)
#define FOR(a, b) for (int i = (a); i < (b); i++)
#define REP(a) for (int j = 0; j < (a); j++)
#define rev(a) for (int i = (a); i >= 0; i--)
#define fr(i, n) for (i = 0; i < n; i++)
#define fr1(i, n, m) for (i = n; i < m; i++)
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue<int> PQ;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
/*
//FUNCTION//
ll bigmod(ll a, ll b, ll c)
{
if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=x*x%c;
if(b%2==1)x=x*a%c;return x;
}
ll poww(ll a, ll b)
{
if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=x*a;return x;
}
ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}
int pr = 10000000;
vi primelist;
bool a[MM*100];
void seive( )
{
int i,j,k=sqrt(pr);
a[1]=1;
primelist.pb(2);
for(i=4;i<=pr;i+=2)a[i]=1;
for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}
ll fact_divs( ll n, ll p)
{
ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}
//*/
const int M = MM * 5;
int a[M], root[M];
int avail;
struct node {
int l, r, val;
node() { l = r = val = 0; }
} sum[M * 50];
int update(int PreNode, int l, int r, int L, int val) {
int NewNode = ++avail;
if (l == r) {
sum[NewNode].val = val;
/// sum[NewNode].val = sum[PreNode].val + val;
return NewNode;
}
int mid = (l + r) / 2;
if (L <= mid) {
sum[NewNode].r = sum[PreNode].r;
sum[NewNode].l = update(sum[PreNode].l, l, mid, L, val);
} else {
sum[NewNode].l = sum[PreNode].l;
sum[NewNode].r = update(sum[PreNode].r, mid + 1, r, L, val);
}
sum[NewNode].val = sum[sum[NewNode].l].val + sum[sum[NewNode].r].val;
return NewNode;
}
ll query(int n, int l, int r, int L, int R) {
if (l > R || r < L)
return 0;
if (l >= L && r <= R)
return sum[n].val;
int mid = (l + r) / 2;
int tot = query(sum[n].l, l, mid, L, R) + query(sum[n].r, mid + 1, r, L, R);
return tot;
}
int idx[M];
int main() {
I_O;
int n, m;
cin >> n >> m;
rep(n) cin >> a[i + 1];
for (int i = 1; i <= n; i++) {
if (idx[a[i]]) {
root[i] = update(root[i - 1], 1, n, idx[a[i]], 0);
root[i] = update(root[i], 1, n, i, 1);
} else {
root[i] = update(root[i - 1], 1, n, i, 1);
}
idx[a[i]] = i;
}
rep(m) {
int l, r;
cin >> l >> r;
cout << query(root[r], 1, n, l, r) << "\n";
}
return 0;
}
| replace | 103 | 104 | 103 | 104 | -11 | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQGI; // 大きい順
typedef priority_queue<int, VI, greater<int>> PQLI;
typedef priority_queue<PII> PQGP;
typedef priority_queue<PII, VPII, greater<int>> PQLP;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EB emplace_back
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define LB lower_bound
#define UB upper_bound
#define NEXP next_permutation
#define FI first
#define SE second
#define Vmin(a) *min_element((a).begin(), (a).end())
#define Vmax(a) *max_element((a).begin(), (a).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REPR(i, n) FORR(i, 0, n)
#define CFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define CREP(i, n) CFOR(i, 0, n)
#define CFORR(i, a, b) for (int i = (b); i >= (a); i--)
#define CREPR(i, n) CFORR(i, 0, n)
#define BFOR(bit, a, b) for (int bit = (a); bit < (1 << (b)); ++bit)
#define BREP(bit, n) BFOR(bit, 0, n)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const LL LINF = LLONG_MAX / 3;
const int RINF = INT_MIN / 2;
const LL RLINF = LLONG_MIN / 3;
const LL MOD = 1e9 + 7;
const LL MODD = 998244353;
const int MAX = 510000;
inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }
// other
//-------------------------------------------
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define COUT(x) cout << (x) << endl
#define COUT2(x, y) cout << (x) << " " << (y) << endl
#define COUT3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define PR(x) cout << (x)
#define ENDL cout << endl
#define SPACE cout << " "
#define BC(x) __builtin_popcountll(x)
VI dx = {1, 0, -1, 0, 1, 1, -1, -1};
VI dy = {0, 1, 0, -1, 1, -1, 1, -1};
LL Gcd(LL a, LL b) { return __gcd(a, b); }
LL Lcm(LL a, LL b) { return a / Gcd(a, b) * b; }
LL ModPow(LL A, LL N, LL M) {
LL res = 1;
while (N > 0) {
if (N & 1)
res = res * A % M;
A = A * A % M;
N >>= 1;
}
return res;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
struct str {
int l, r, q;
str(int l, int r, int q) : l(l), r(r), q(q) {}
};
template <typename T> struct SegmentTree {
using OP = function<T(T, T)>;
int n;
vector<T> node;
T t;
OP op;
SegmentTree(int n_, T t, OP op) : t(t), op(op) {
n = 1;
while (n < n_)
n <<= 1;
node.assign(2 * n, t);
}
void init(int n_) {
n = 1;
while (n < n_)
n <<= 1;
node.assign(2 * n, t);
}
void set(int k, T x) { node.at(k + n) = x; }
void build() {
for (int k = n - 1; k > 0; k--) {
node.at(k) = op(node.at(2 * k), node.at(2 * k + 1));
}
}
void update(int k, T x) {
k += n;
node.at(k) = x;
while (k >>= 1) {
node.at(k) = op(node.at(2 * k), node.at(2 * k + 1));
}
}
void update(int l, int r, T x) { FOR(k, l, r) update(k, x); }
T at(int k) { return node.at(k + n); }
void add(int k, T a) {
T x = at(k) + a;
update(k, x);
}
T query(int a, int b) {
T L = t, R = t;
for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = op(L, node.at(a++));
if (b & 1)
R = op(node.at(--b), R);
}
return op(L, R);
}
template <typename C> int findR(int a, int b, C &check) {
return findR(a, b, check, 1, 0, n);
}
template <typename C> int findR(int a, int b, C &check, int k, int l, int r) {
if (!check(node.at(k)) || r <= a || b <= l)
return -1;
if (k >= n)
return k - n;
int rv = findR(a, b, check, 2 * k + 1, (l + r) / 2, r);
if (rv != -1)
return rv;
return findR(a, b, check, 2 * k, l, (l + r) / 2);
}
template <typename C> int findL(int a, int b, C &check) {
return findL(a, b, check, 1, 0, n);
}
template <typename C> int findL(int a, int b, C &check, int k, int l, int r) {
if (!check(node.at(k)) || r <= a || b <= l)
return -1;
if (k >= n)
return k - n;
int lv = findL(a, b, check, 2 * k, l, (l + r) / 2);
if (lv != -1)
return lv;
return findL(a, b, check, 2 * k + 1, (l + r) / 2, r);
}
};
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N, Q;
cin >> N >> Q;
VI c(N);
cin >> c;
VI lastap(N, N + 5);
REP(i, N) { c.at(i)--; }
vector<str> vq;
VI ans(Q);
REP(i, Q) {
int l, r;
cin >> l >> r;
vq.EB(--l, --r, i);
}
sort(ALL(vq), [](auto a, auto b) { return a.r < b.r; });
int R = -1;
SegmentTree<int> seg(N + 10, 0, [](int a, int b) { return a + b; });
REP(q, Q) {
if (R < vq.at(q).r) {
for (int i = R + 1; i <= vq.at(q).r; ++i) {
seg.add(lastap.at(c.at(i)), -1);
lastap.at(c.at(i)) = i;
seg.add(lastap.at(c.at(i)), 1);
}
}
int res = seg.query(vq.at(q).l, vq.at(q).r + 1);
ans.at(vq.at(q).q) = res;
}
REP(i, Q) COUT(ans.at(i));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQGI; // 大きい順
typedef priority_queue<int, VI, greater<int>> PQLI;
typedef priority_queue<PII> PQGP;
typedef priority_queue<PII, VPII, greater<int>> PQLP;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EB emplace_back
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define LB lower_bound
#define UB upper_bound
#define NEXP next_permutation
#define FI first
#define SE second
#define Vmin(a) *min_element((a).begin(), (a).end())
#define Vmax(a) *max_element((a).begin(), (a).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REPR(i, n) FORR(i, 0, n)
#define CFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define CREP(i, n) CFOR(i, 0, n)
#define CFORR(i, a, b) for (int i = (b); i >= (a); i--)
#define CREPR(i, n) CFORR(i, 0, n)
#define BFOR(bit, a, b) for (int bit = (a); bit < (1 << (b)); ++bit)
#define BREP(bit, n) BFOR(bit, 0, n)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const LL LINF = LLONG_MAX / 3;
const int RINF = INT_MIN / 2;
const LL RLINF = LLONG_MIN / 3;
const LL MOD = 1e9 + 7;
const LL MODD = 998244353;
const int MAX = 510000;
inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }
// other
//-------------------------------------------
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define COUT(x) cout << (x) << endl
#define COUT2(x, y) cout << (x) << " " << (y) << endl
#define COUT3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define PR(x) cout << (x)
#define ENDL cout << endl
#define SPACE cout << " "
#define BC(x) __builtin_popcountll(x)
VI dx = {1, 0, -1, 0, 1, 1, -1, -1};
VI dy = {0, 1, 0, -1, 1, -1, 1, -1};
LL Gcd(LL a, LL b) { return __gcd(a, b); }
LL Lcm(LL a, LL b) { return a / Gcd(a, b) * b; }
LL ModPow(LL A, LL N, LL M) {
LL res = 1;
while (N > 0) {
if (N & 1)
res = res * A % M;
A = A * A % M;
N >>= 1;
}
return res;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
struct str {
int l, r, q;
str(int l, int r, int q) : l(l), r(r), q(q) {}
};
template <typename T> struct SegmentTree {
using OP = function<T(T, T)>;
int n;
vector<T> node;
T t;
OP op;
SegmentTree(int n_, T t, OP op) : t(t), op(op) {
n = 1;
while (n < n_)
n <<= 1;
node.assign(2 * n, t);
}
void init(int n_) {
n = 1;
while (n < n_)
n <<= 1;
node.assign(2 * n, t);
}
void set(int k, T x) { node.at(k + n) = x; }
void build() {
for (int k = n - 1; k > 0; k--) {
node.at(k) = op(node.at(2 * k), node.at(2 * k + 1));
}
}
void update(int k, T x) {
k += n;
node.at(k) = x;
while (k >>= 1) {
node.at(k) = op(node.at(2 * k), node.at(2 * k + 1));
}
}
void update(int l, int r, T x) { FOR(k, l, r) update(k, x); }
T at(int k) { return node.at(k + n); }
void add(int k, T a) {
T x = at(k) + a;
update(k, x);
}
T query(int a, int b) {
T L = t, R = t;
for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = op(L, node.at(a++));
if (b & 1)
R = op(node.at(--b), R);
}
return op(L, R);
}
template <typename C> int findR(int a, int b, C &check) {
return findR(a, b, check, 1, 0, n);
}
template <typename C> int findR(int a, int b, C &check, int k, int l, int r) {
if (!check(node.at(k)) || r <= a || b <= l)
return -1;
if (k >= n)
return k - n;
int rv = findR(a, b, check, 2 * k + 1, (l + r) / 2, r);
if (rv != -1)
return rv;
return findR(a, b, check, 2 * k, l, (l + r) / 2);
}
template <typename C> int findL(int a, int b, C &check) {
return findL(a, b, check, 1, 0, n);
}
template <typename C> int findL(int a, int b, C &check, int k, int l, int r) {
if (!check(node.at(k)) || r <= a || b <= l)
return -1;
if (k >= n)
return k - n;
int lv = findL(a, b, check, 2 * k, l, (l + r) / 2);
if (lv != -1)
return lv;
return findL(a, b, check, 2 * k + 1, (l + r) / 2, r);
}
};
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N, Q;
cin >> N >> Q;
VI c(N);
cin >> c;
VI lastap(N, N + 5);
REP(i, N) { c.at(i)--; }
vector<str> vq;
VI ans(Q);
REP(i, Q) {
int l, r;
cin >> l >> r;
vq.EB(--l, --r, i);
}
sort(ALL(vq), [](auto a, auto b) { return a.r < b.r; });
int R = -1;
SegmentTree<int> seg(N + 10, 0, [](int a, int b) { return a + b; });
REP(q, Q) {
if (R < vq.at(q).r) {
for (int i = R + 1; i <= vq.at(q).r; ++i) {
seg.add(lastap.at(c.at(i)), -1);
lastap.at(c.at(i)) = i;
seg.add(lastap.at(c.at(i)), 1);
}
R = vq.at(q).r;
}
int res = seg.query(vq.at(q).l, vq.at(q).r + 1);
ans.at(vq.at(q).q) = res;
}
REP(i, Q) COUT(ans.at(i));
return 0;
}
| insert | 299 | 299 | 299 | 300 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define ll long long
#define prl pair<ll, ll>
#define pri pair<int, int>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define db double
#define N 100005
#define mod 1000000007
#define INF 2147483647
using namespace std;
mt19937 mrand(random_device{}());
uniform_int_distribution<ll> dist(0, 100000000);
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
ll qpow(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
int n;
int a[N], c[N]; // 对应原数组和树状数组
inline int lowbit(int x) { return x & (-x); }
void modify(int i, int k) { // 在i位置加上k
while (i <= n) {
c[i] += k;
i += lowbit(i);
}
}
int getsum(int i) { // 求A[1 - i]的和
int res = 0;
while (i > 0) {
res += c[i];
i -= lowbit(i);
}
return res;
}
int loc[N];
struct query {
int l, r, id;
bool operator<(query &b) { return r < b.r; }
} Q[N];
int ans[N];
int main() {
IOS;
int q;
cin >> n >> q;
rep(i, 1, n + 1) { cin >> a[i]; }
rep(i, 0, q) {
cin >> Q[i].l >> Q[i].r;
Q[i].id = i + 1;
}
sort(Q, Q + q);
int cur = 0;
rep(i, 1, n + 1) {
if (loc[a[i]]) {
modify(loc[a[i]], -1);
}
modify(i, 1);
loc[a[i]] = i;
while (cur < q && Q[cur].r == i) {
ans[Q[cur].id] = getsum(i);
if (Q[cur].l > 1)
ans[Q[cur].id] -= getsum(Q[cur].l - 1);
cur++;
}
if (cur == q)
break;
}
rep(i, 1, q + 1) cout << ans[i] << '\n';
return 0;
} | #include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define ll long long
#define prl pair<ll, ll>
#define pri pair<int, int>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define db double
#define N 1000005
#define mod 1000000007
#define INF 2147483647
using namespace std;
mt19937 mrand(random_device{}());
uniform_int_distribution<ll> dist(0, 100000000);
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
ll qpow(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
int n;
int a[N], c[N]; // 对应原数组和树状数组
inline int lowbit(int x) { return x & (-x); }
void modify(int i, int k) { // 在i位置加上k
while (i <= n) {
c[i] += k;
i += lowbit(i);
}
}
int getsum(int i) { // 求A[1 - i]的和
int res = 0;
while (i > 0) {
res += c[i];
i -= lowbit(i);
}
return res;
}
int loc[N];
struct query {
int l, r, id;
bool operator<(query &b) { return r < b.r; }
} Q[N];
int ans[N];
int main() {
IOS;
int q;
cin >> n >> q;
rep(i, 1, n + 1) { cin >> a[i]; }
rep(i, 0, q) {
cin >> Q[i].l >> Q[i].r;
Q[i].id = i + 1;
}
sort(Q, Q + q);
int cur = 0;
rep(i, 1, n + 1) {
if (loc[a[i]]) {
modify(loc[a[i]], -1);
}
modify(i, 1);
loc[a[i]] = i;
while (cur < q && Q[cur].r == i) {
ans[Q[cur].id] = getsum(i);
if (Q[cur].l > 1)
ans[Q[cur].id] -= getsum(Q[cur].l - 1);
cur++;
}
if (cur == q)
break;
}
rep(i, 1, q + 1) cout << ans[i] << '\n';
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define per(i, a, n) for (int i = (a); i > (n); i--)
typedef long long ll;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int block, curl, curr, res;
struct qry {
int id, l, r;
} q[maxn];
int ans[maxn], a[maxn];
unordered_map<int, int> mp;
void add(int pos) {
if (mp[a[pos]] == 0) {
res++;
mp[a[pos]] = 1;
} else {
mp[a[pos]]++;
}
}
void del(int pos) {
if (mp[a[pos]] - 1 == 0) {
mp[a[pos]] = 0;
res--;
} else {
mp[a[pos]]--;
}
}
void solve() {
ll n, m;
cin >> n >> m;
block = sqrt(n);
rep(i, 1, n + 1) cin >> a[i];
rep(i, 1, m + 1) cin >> q[i].l >> q[i].r, q[i].id = i;
sort(q + 1, q + m + 1, [](qry x, qry y) {
if (x.l / block == y.l / block)
return x.r < y.r;
return x.l / block < y.l / block;
});
curl = curr = res = 0;
for (int i = 1; i <= m; i++) {
while (curr > q[i].r)
del(curr--);
while (curr < q[i].r)
add(++curr);
while (curl > q[i].l)
add(--curl);
while (curl < q[i].l)
del(curl++);
ans[q[i].id] = res;
}
for (int i = 1; i <= m; i++)
cout << ans[i] << '\n';
}
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef DEBUG
freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
// freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif
// int t; cin >> t; while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define per(i, a, n) for (int i = (a); i > (n); i--)
typedef long long ll;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int block, curl, curr, res;
struct qry {
int id, l, r;
} q[maxn];
int ans[maxn], a[maxn], mp[maxn];
void add(int pos) {
if (mp[a[pos]] == 0) {
res++;
mp[a[pos]] = 1;
} else {
mp[a[pos]]++;
}
}
void del(int pos) {
if (mp[a[pos]] - 1 == 0) {
mp[a[pos]] = 0;
res--;
} else {
mp[a[pos]]--;
}
}
void solve() {
ll n, m;
cin >> n >> m;
block = sqrt(n);
rep(i, 1, n + 1) cin >> a[i];
rep(i, 1, m + 1) cin >> q[i].l >> q[i].r, q[i].id = i;
sort(q + 1, q + m + 1, [](qry x, qry y) {
if (x.l / block == y.l / block)
return x.r < y.r;
return x.l / block < y.l / block;
});
curl = curr = res = 0;
for (int i = 1; i <= m; i++) {
while (curr > q[i].r)
del(curr--);
while (curr < q[i].r)
add(++curr);
while (curl > q[i].l)
add(--curl);
while (curl < q[i].l)
del(curl++);
ans[q[i].id] = res;
}
for (int i = 1; i <= m; i++)
cout << ans[i] << '\n';
}
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef DEBUG
freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
// freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif
// int t; cin >> t; while(t--)
solve();
return 0;
} | replace | 13 | 16 | 13 | 14 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define all(v) v.begin(), v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout << #x << " is " << x << endl;
using namespace std;
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
// assert(b>=0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int mxn = 1e5 + 1;
int fin[mxn];
int lst[mxn];
int n, q;
vector<int> c;
void update(int ind, int val) {
while (ind <= n) {
fin[ind] += val;
ind += ind & -ind;
}
}
int query(int ind) {
int ret = 0;
while (ind > 0) {
ret += fin[ind];
ind -= ind & -ind;
}
return ret;
}
struct Query {
int l, r, ind;
bool operator()(Query a, Query b) { return a.r < b.r; }
};
void solve() {
memset(lst, -1, sizeof(lst));
cin >> n >> q;
int ans[q];
c.resize(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
Query qry[q];
for (int i = 0; i < q; i++) {
qry[i].ind = i;
cin >> qry[i].l >> qry[i].r;
qry[i].l--, qry[i].r--;
}
sort(qry, qry + q, Query());
for (int j = 0, i = 0; i < n; i++) {
if (lst[c[i]] != -1) {
update(lst[c[i]] + 1, -1);
}
lst[c[i]] = i;
update(i + 1, 1);
while (j < q && qry[j].r == i) {
ans[qry[j].ind] = query(qry[j].r + 1) - query(qry[j].l);
j++;
}
}
for (int i = 0; i < q; i++) {
cout << ans[i] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
// cin>>tc;
while (tc--)
solve();
}
| #include <bits/stdc++.h>
#define ll long long
#define all(v) v.begin(), v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout << #x << " is " << x << endl;
using namespace std;
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
// assert(b>=0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int mxn = 5e5 + 1;
int fin[mxn];
int lst[mxn];
int n, q;
vector<int> c;
void update(int ind, int val) {
while (ind <= n) {
fin[ind] += val;
ind += ind & -ind;
}
}
int query(int ind) {
int ret = 0;
while (ind > 0) {
ret += fin[ind];
ind -= ind & -ind;
}
return ret;
}
struct Query {
int l, r, ind;
bool operator()(Query a, Query b) { return a.r < b.r; }
};
void solve() {
memset(lst, -1, sizeof(lst));
cin >> n >> q;
int ans[q];
c.resize(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
Query qry[q];
for (int i = 0; i < q; i++) {
qry[i].ind = i;
cin >> qry[i].l >> qry[i].r;
qry[i].l--, qry[i].r--;
}
sort(qry, qry + q, Query());
for (int j = 0, i = 0; i < n; i++) {
if (lst[c[i]] != -1) {
update(lst[c[i]] + 1, -1);
}
lst[c[i]] = i;
update(i + 1, 1);
while (j < q && qry[j].r == i) {
ans[qry[j].ind] = query(qry[j].r + 1) - query(qry[j].l);
j++;
}
}
for (int i = 0; i < q; i++) {
cout << ans[i] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
// cin>>tc;
while (tc--)
solve();
}
| replace | 97 | 98 | 97 | 98 | 0 | |
p02599 | C++ | Time Limit Exceeded | #pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<long long, long long> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
const int MAX_N = 500000;
int cnt[MAX_N];
int C[MAX_N];
int ans = 0;
// void init(int N) { cnt = vi(N, 0); }
void add(int p) {
// pの位置をクエリ範囲に加えるときの処理
if (cnt[C[p]]++ == 0)
ans++;
}
void del(int p) {
// pの位置をクエリ範囲から除くときの処理
if (--cnt[C[p]] == 0)
ans--;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int i, j, k;
int N, Q;
cin >> N >> Q;
for (i = 0; i < N; i++) {
int c;
cin >> c;
C[i] = c;
}
// init(N);
vector<pi> LR(Q);
for (i = 0; i < Q; i++) {
int l, r;
cin >> l >> r;
l--;
LR[i] = pi(l, r);
}
vi qi(Q);
for (i = 0; i < Q; i++) {
qi[i] = i;
}
int sq = sqrt(N);
sort(qi.begin(), qi.end(), [&](int i, int j) {
if (LR[i].first / sq != LR[j].first / sq)
return LR[i].first < LR[j].first;
return LR[i].second < LR[j].second;
// return bool((LR[i].second < LR[j].second) ^ (LR[i].first / sq % 2));
});
int nl = 0, nr = 0;
vi vans(Q);
for (auto i : qi) {
while (nl > LR[i].first)
add(--nl);
while (nr < LR[i].second)
add(nr++);
while (nl < LR[i].first)
del(nl++);
while (nr > LR[i].second)
del(--nr);
vans[i] = ans;
}
for (i = 0; i < Q; i++) {
cout << vans[i] << "\n";
}
return 0;
}
| #pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<long long, long long> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
const int MAX_N = 500000;
int cnt[MAX_N];
int C[MAX_N];
int ans = 0;
// void init(int N) { cnt = vi(N, 0); }
void add(int p) {
// pの位置をクエリ範囲に加えるときの処理
if (cnt[C[p]]++ == 0)
ans++;
}
void del(int p) {
// pの位置をクエリ範囲から除くときの処理
if (--cnt[C[p]] == 0)
ans--;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int i, j, k;
int N, Q;
cin >> N >> Q;
for (i = 0; i < N; i++) {
int c;
cin >> c;
C[i] = c;
}
// init(N);
vector<pi> LR(Q);
for (i = 0; i < Q; i++) {
int l, r;
cin >> l >> r;
l--;
LR[i] = pi(l, r);
}
vi qi(Q);
for (i = 0; i < Q; i++) {
qi[i] = i;
}
int sq = sqrt(N);
sort(qi.begin(), qi.end(), [&](int i, int j) {
if (LR[i].first / sq != LR[j].first / sq)
return LR[i].first < LR[j].first;
// return LR[i].second < LR[j].second;
return bool((LR[i].second < LR[j].second) ^ (LR[i].first / sq % 2));
});
int nl = 0, nr = 0;
vi vans(Q);
for (auto i : qi) {
while (nl > LR[i].first)
add(--nl);
while (nr < LR[i].second)
add(nr++);
while (nl < LR[i].first)
del(nl++);
while (nr > LR[i].second)
del(--nr);
vans[i] = ans;
}
for (i = 0; i < Q; i++) {
cout << vans[i] << "\n";
}
return 0;
}
| replace | 72 | 74 | 72 | 74 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
#define Fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define Freed freopen("0in.txt", "r", stdin);
#define Fout freopen("0out.txt", "w", stdout);
#define ll long long
#define pb push_back
#define mp make_pair
#define Mod 1000000007
#define limit 200008
using namespace std;
int n, cnt[limit], ans[limit], List[limit];
struct str {
int l, r, ind;
};
bool cmp(str a, str b) { return a.r < b.r; }
str query[limit];
void up(int ind, int key) {
while (ind <= n) {
cnt[ind] += key;
ind += (ind & -ind);
}
}
int qu(int ind) {
int sum = 0;
while (ind > 0) {
sum += cnt[ind];
ind -= (ind & -ind);
}
return sum;
}
void solve(int t) {
int i, j, q, m, k, l, r; /// Binary index tree
for (i = 0; i < limit; i++) {
List[i] = -1;
cnt[i] = 0;
ans[i] = 0;
}
cin >> n >> q;
int D[n + 5];
for (i = 1; i <= n; i++)
cin >> D[i];
for (i = 1; i <= q; i++) {
cin >> l >> r;
query[i].l = l;
query[i].r = r;
query[i].ind = i;
}
sort(query + 1, query + q + 1, cmp);
k = 1;
for (i = 1; i <= n; i++) {
if (List[D[i]] != -1) {
up(List[D[i]], -1);
}
List[D[i]] = i;
up(i, 1);
while (k <= q &&
query[k].r == i) { // cout <<k<<" "<<qu(query[k].r)<<"
// "<<qu(query[k].l-1)<<" "<<query[k].ind<<endl;
ans[query[k].ind] = qu(query[k].r) - qu(query[k].l - 1);
k++;
}
}
for (i = 1; i <= q; i++)
cout << ans[i] << endl;
}
int main() {
// Fast
// Freed
// Fout
int tt = 1, t;
// cin >> tt;
for (t = 1; t <= tt; t++)
solve(t);
return 0;
}
| #include <bits/stdc++.h>
#define Fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define Freed freopen("0in.txt", "r", stdin);
#define Fout freopen("0out.txt", "w", stdout);
#define ll long long
#define pb push_back
#define mp make_pair
#define Mod 1000000007
#define limit 500008
using namespace std;
int n, cnt[limit], ans[limit], List[limit];
struct str {
int l, r, ind;
};
bool cmp(str a, str b) { return a.r < b.r; }
str query[limit];
void up(int ind, int key) {
while (ind <= n) {
cnt[ind] += key;
ind += (ind & -ind);
}
}
int qu(int ind) {
int sum = 0;
while (ind > 0) {
sum += cnt[ind];
ind -= (ind & -ind);
}
return sum;
}
void solve(int t) {
int i, j, q, m, k, l, r; /// Binary index tree
for (i = 0; i < limit; i++) {
List[i] = -1;
cnt[i] = 0;
ans[i] = 0;
}
cin >> n >> q;
int D[n + 5];
for (i = 1; i <= n; i++)
cin >> D[i];
for (i = 1; i <= q; i++) {
cin >> l >> r;
query[i].l = l;
query[i].r = r;
query[i].ind = i;
}
sort(query + 1, query + q + 1, cmp);
k = 1;
for (i = 1; i <= n; i++) {
if (List[D[i]] != -1) {
up(List[D[i]], -1);
}
List[D[i]] = i;
up(i, 1);
while (k <= q &&
query[k].r == i) { // cout <<k<<" "<<qu(query[k].r)<<"
// "<<qu(query[k].l-1)<<" "<<query[k].ind<<endl;
ans[query[k].ind] = qu(query[k].r) - qu(query[k].l - 1);
k++;
}
}
for (i = 1; i <= q; i++)
cout << ans[i] << endl;
}
int main() {
// Fast
// Freed
// Fout
int tt = 1, t;
// cin >> tt;
for (t = 1; t <= tt; t++)
solve(t);
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 lll;
#define print(i) cout << "debug: " << i << endl
#define close() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, b) memset(a, b, sizeof(a))
const ll mod = 1e9 + 7;
const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
struct node {
int l, r, sum;
node(int l = 0, int r = 0, int sum = 0) : l(l), r(r), sum(sum){};
} t[maxn * 50];
int root[maxn];
int tot;
void build(int &tar, int l, int r) {
tar = ++tot;
t[tar].sum = 0;
if (l == r)
return;
int mid = l + r >> 1;
build(t[tar].l, l, mid), build(t[tar].r, mid + 1, r);
}
void update(int pre, int &now, int l, int r, int pos, int val) {
now = ++tot;
t[now] = t[pre];
t[now].sum += val;
if (l == r)
return;
int mid = l + r >> 1;
if (pos <= mid)
update(t[pre].l, t[now].l, l, mid, pos, val);
else
update(t[pre].r, t[now].r, mid + 1, r, pos, val);
}
int query(int posl, int tar, int l, int r) {
if (l == r)
return t[tar].sum;
int mid = l + r >> 1;
if (posl <= mid)
return t[t[tar].r].sum + query(posl, t[tar].l, l, mid);
else
return query(posl, t[tar].r, mid + 1, r);
}
map<int, int> vis;
int main() {
close();
int n, q;
cin >> n >> q;
build(root[0], 1, n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (!vis[x])
vis[x] = i, update(root[i - 1], root[i], 1, n, i, 1);
else
update(root[i - 1], root[i], 1, n, vis[x], -1),
vis[x] = i, update(root[i], root[i], 1, n, i, 1);
}
while (q--) {
int l, r;
scanf("%d%d", &l, &r);
cout << query(l, root[r], 1, n) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 lll;
#define print(i) cout << "debug: " << i << endl
#define close() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, b) memset(a, b, sizeof(a))
const ll mod = 1e9 + 7;
const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
struct node {
int l, r, sum;
node(int l = 0, int r = 0, int sum = 0) : l(l), r(r), sum(sum){};
} t[maxn * 50];
int root[maxn];
int tot;
void build(int &tar, int l, int r) {
tar = ++tot;
t[tar].sum = 0;
if (l == r)
return;
int mid = l + r >> 1;
build(t[tar].l, l, mid), build(t[tar].r, mid + 1, r);
}
void update(int pre, int &now, int l, int r, int pos, int val) {
now = ++tot;
t[now] = t[pre];
t[now].sum += val;
if (l == r)
return;
int mid = l + r >> 1;
if (pos <= mid)
update(t[pre].l, t[now].l, l, mid, pos, val);
else
update(t[pre].r, t[now].r, mid + 1, r, pos, val);
}
int query(int posl, int tar, int l, int r) {
if (l == r)
return t[tar].sum;
int mid = l + r >> 1;
if (posl <= mid)
return t[t[tar].r].sum + query(posl, t[tar].l, l, mid);
else
return query(posl, t[tar].r, mid + 1, r);
}
map<int, int> vis;
int main() {
close();
int n, q;
scanf("%d%d", &n, &q);
build(root[0], 1, n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (!vis[x])
vis[x] = i, update(root[i - 1], root[i], 1, n, i, 1);
else
update(root[i - 1], root[i], 1, n, vis[x], -1),
vis[x] = i, update(root[i], root[i], 1, n, i, 1);
}
while (q--) {
int l, r;
scanf("%d%d", &l, &r);
cout << query(l, root[r], 1, n) << endl;
}
} | replace | 53 | 54 | 53 | 54 | -11 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int n, m;
struct Tree {
int ls, rs, val;
} tre[maxn * 40];
int idx = 0, root[maxn];
int build(int l, int r) {
int nod = ++idx;
tre[nod].val = 0;
if (l == r)
return nod;
int mid = (l + r) >> 1;
tre[nod].ls = build(l, mid);
tre[nod].rs = build(mid + 1, r);
return nod;
}
int update(int pre, int l, int r, int pos, int v) {
int nod = ++idx;
tre[nod] = tre[pre];
tre[nod].val += v;
if (l == r)
return nod;
int mid = (l + r) >> 1;
if (pos <= mid)
tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
else
tre[nod].rs = update(tre[pre].rs, mid + 1, r, pos, v);
return nod;
}
int query(int id, int l, int r, int pos) {
if (l == r)
return tre[id].val;
int mid = (l + r) >> 1;
if (pos <= mid) {
return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
} else
return query(tre[id].rs, mid + 1, r, pos);
}
int a[maxn], vis[maxn];
void solve() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
root[0] = build(1, n);
for (int i = 1; i <= n; i++) {
if (!vis[a[i]])
root[i] = update(root[i - 1], 1, n, i, 1);
else {
int t = update(root[i - 1], 1, n, vis[a[i]], -1);
root[i] = update(t, 1, n, i, 1);
}
vis[a[i]] = i;
}
while (m--) {
int l, r;
scanf("%d%d", &l, &r);
int tmp = query(root[r], 1, n, l);
printf("%d\n", tmp);
}
}
int main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int n, m;
struct Tree {
int ls, rs, val;
} tre[maxn * 50];
int idx = 0, root[maxn];
int build(int l, int r) {
int nod = ++idx;
tre[nod].val = 0;
if (l == r)
return nod;
int mid = (l + r) >> 1;
tre[nod].ls = build(l, mid);
tre[nod].rs = build(mid + 1, r);
return nod;
}
int update(int pre, int l, int r, int pos, int v) {
int nod = ++idx;
tre[nod] = tre[pre];
tre[nod].val += v;
if (l == r)
return nod;
int mid = (l + r) >> 1;
if (pos <= mid)
tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
else
tre[nod].rs = update(tre[pre].rs, mid + 1, r, pos, v);
return nod;
}
int query(int id, int l, int r, int pos) {
if (l == r)
return tre[id].val;
int mid = (l + r) >> 1;
if (pos <= mid) {
return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
} else
return query(tre[id].rs, mid + 1, r, pos);
}
int a[maxn], vis[maxn];
void solve() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
root[0] = build(1, n);
for (int i = 1; i <= n; i++) {
if (!vis[a[i]])
root[i] = update(root[i - 1], 1, n, i, 1);
else {
int t = update(root[i - 1], 1, n, vis[a[i]], -1);
root[i] = update(t, 1, n, i, 1);
}
vis[a[i]] = i;
}
while (m--) {
int l, r;
scanf("%d%d", &l, &r);
int tmp = query(root[r], 1, n, l);
printf("%d\n", tmp);
}
}
int main() {
solve();
return 0;
}
| replace | 6 | 7 | 6 | 7 | -11 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// int/long: -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long: -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)
#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2
#define MOD 1000000007
#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())
#define BIT_MAX 500001
// Vector starting from 1
// index ==0 -> dummy, not used
vector<int> BIT(BIT_MAX + 1);
void add_BIT(int ix, const int &v) {
while (ix <= BIT_MAX) {
BIT.at(ix) += v;
ix += ix & -ix;
}
}
int sum_BIT(int ix) {
int S = 0;
while (ix > 0) {
S += BIT.at(ix);
ix -= ix & -ix;
}
return S;
}
void F(const int r, int &rr, const vector<int> &c, vector<int> &R) {
while (rr < r) {
rr++;
int C = c.at(rr);
if (0 != R.at(C))
add_BIT(R.at(C), -1);
add_BIT(rr, 1);
R.at(C) = rr;
}
return;
}
int main() {
int N, Q;
cin >> N >> Q;
vector<int> c(N + 1, 0);
Rep1(i, N) cin >> c.at(i);
vector<vector<int>> q;
Rep0(i, Q) {
int l, r;
cin >> l >> r;
q.push_back({r, l, i});
}
Sort(q);
//
vector<int> R(N, 0);
vector<int> ANS(Q, 0);
int r0 = 0;
Rep0(i, Q) {
int r = q.at(i).at(0);
int l = q.at(i).at(1);
int j = q.at(i).at(2);
F(r, r0, c, R);
ANS.at(j) = sum_BIT(r) - sum_BIT(l - 1);
}
Rep0(i, Q) cout << ANS.at(i) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// int/long: -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long: -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)
#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2
#define MOD 1000000007
#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())
#define BIT_MAX 500001
// Vector starting from 1
// index ==0 -> dummy, not used
vector<int> BIT(BIT_MAX + 1);
void add_BIT(int ix, const int &v) {
while (ix <= BIT_MAX) {
BIT.at(ix) += v;
ix += ix & -ix;
}
}
int sum_BIT(int ix) {
int S = 0;
while (ix > 0) {
S += BIT.at(ix);
ix -= ix & -ix;
}
return S;
}
void F(const int r, int &rr, const vector<int> &c, vector<int> &R) {
while (rr < r) {
rr++;
int C = c.at(rr);
if (0 != R.at(C))
add_BIT(R.at(C), -1);
add_BIT(rr, 1);
R.at(C) = rr;
}
return;
}
int main() {
int N, Q;
cin >> N >> Q;
vector<int> c(N + 1, 0);
Rep1(i, N) cin >> c.at(i);
vector<vector<int>> q;
Rep0(i, Q) {
int l, r;
cin >> l >> r;
q.push_back({r, l, i});
}
Sort(q);
//
vector<int> R(N + 1, 0);
vector<int> ANS(Q, 0);
int r0 = 0;
Rep0(i, Q) {
int r = q.at(i).at(0);
int l = q.at(i).at(1);
int j = q.at(i).at(2);
F(r, r0, c, R);
ANS.at(j) = sum_BIT(r) - sum_BIT(l - 1);
}
Rep0(i, Q) cout << ANS.at(i) << endl;
return 0;
}
| replace | 66 | 67 | 66 | 67 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 502020;
constexpr int MAX_ROOT = 20000000;
// https://github.com/anh1l1ator/Spoj/blob/master/Desktop/Codes/DQUERY_Online.cpp
struct Node {
int cnt, L, R;
Node() {
cnt = 0;
L = R = -1;
}
Node(int x, int y, int z) { L = x, R = y, cnt = z; }
} tree[MAX_ROOT];
class DistinctElements {
int gc = 0, N;
vector<int> rt;
int build(int L, int R) {
gc++;
if (L == R)
return gc;
int x = gc;
tree[x] = Node(build(L, (L + R) / 2), build((L + R) / 2 + 1, R), 0);
return x;
}
int update(int L, int R, int root, int idx, int val) {
assert(root < MAX_ROOT);
if (L > idx || R < idx) {
return root;
}
gc++;
if (L == idx && R == idx) {
tree[gc] = Node(-1, -1, tree[root].cnt + val);
return gc;
}
int x = gc;
tree[x] = Node(update(L, (L + R) / 2, tree[root].L, idx, val),
update((L + R) / 2 + 1, R, tree[root].R, idx, val),
tree[root].cnt + val);
return x;
}
int query(int L, int R, int root, int ql, int qr) {
if (qr < L || ql > R)
return 0;
if (ql <= L && R <= qr) {
return tree[root].cnt;
}
return query(L, (L + R) / 2, tree[root].L, ql, qr) +
query((L + R) / 2 + 1, R, tree[root].R, ql, qr);
}
int query1idx(int l, int r) { return query(1, N, rt[r], l, r); }
public:
DistinctElements(const vector<int> &as) {
N = as.size();
rt = vector<int>(MAX_N);
vector<int> G(1 << 20, -1);
rt[0] = build(1, N);
for (int i = 1; i <= N; i++) {
int p = rt[i - 1];
if (G[as[i - 1]] != -1) {
p = update(1, N, p, G[as[i - 1]], -1);
}
rt[i] = update(1, N, p, i, 1);
G[as[i - 1]] = i;
}
}
int query(int l, int r) { return query1idx(l + 1, r); }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> cs(n);
for (int i = 0; i < n; i++)
cin >> cs[i];
DistinctElements hoge(cs);
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
l--;
cout << hoge.query(l, r) << '\n';
}
}
| #include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 502020;
constexpr int MAX_ROOT = 23000000;
// https://github.com/anh1l1ator/Spoj/blob/master/Desktop/Codes/DQUERY_Online.cpp
struct Node {
int cnt, L, R;
Node() {
cnt = 0;
L = R = -1;
}
Node(int x, int y, int z) { L = x, R = y, cnt = z; }
} tree[MAX_ROOT];
class DistinctElements {
int gc = 0, N;
vector<int> rt;
int build(int L, int R) {
gc++;
if (L == R)
return gc;
int x = gc;
tree[x] = Node(build(L, (L + R) / 2), build((L + R) / 2 + 1, R), 0);
return x;
}
int update(int L, int R, int root, int idx, int val) {
assert(root < MAX_ROOT);
if (L > idx || R < idx) {
return root;
}
gc++;
if (L == idx && R == idx) {
tree[gc] = Node(-1, -1, tree[root].cnt + val);
return gc;
}
int x = gc;
tree[x] = Node(update(L, (L + R) / 2, tree[root].L, idx, val),
update((L + R) / 2 + 1, R, tree[root].R, idx, val),
tree[root].cnt + val);
return x;
}
int query(int L, int R, int root, int ql, int qr) {
if (qr < L || ql > R)
return 0;
if (ql <= L && R <= qr) {
return tree[root].cnt;
}
return query(L, (L + R) / 2, tree[root].L, ql, qr) +
query((L + R) / 2 + 1, R, tree[root].R, ql, qr);
}
int query1idx(int l, int r) { return query(1, N, rt[r], l, r); }
public:
DistinctElements(const vector<int> &as) {
N = as.size();
rt = vector<int>(MAX_N);
vector<int> G(1 << 20, -1);
rt[0] = build(1, N);
for (int i = 1; i <= N; i++) {
int p = rt[i - 1];
if (G[as[i - 1]] != -1) {
p = update(1, N, p, G[as[i - 1]], -1);
}
rt[i] = update(1, N, p, i, 1);
G[as[i - 1]] = i;
}
}
int query(int l, int r) { return query1idx(l + 1, r); }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> cs(n);
for (int i = 0; i < n; i++)
cin >> cs[i];
DistinctElements hoge(cs);
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
l--;
cout << hoge.query(l, r) << '\n';
}
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) \
vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end())))
#define Sort(vec) sort(vec.begin(), vec.end())
#define RSort(vec) sort(vec.rbegin(), vec.rend())
#define endl "\n"
#define tr1(i) cout << i << endl;
#define tr2(i, j) cout << i << " " << j << endl;
#define tr3(i, j, k) cout << i << " " << j << " " << k << endl;
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define all(st) st.begin(), st.end()
#define vpl vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define al vector<list<int>>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repit(st) for (auto it = st.begin(); it != st.end(); it++)
#define cs(ans) \
; \
cout << setprecision(20) << fixed << ans << endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e16)
#define inf 1e16
#define f first
#define se second
ll mod = 1e9 + 7;
using namespace std;
using namespace __gnu_pbds;
ll mi(ll n, ll m) {
ll pw = n % m;
ll ex = m - 2;
ll ans = 1;
while (ex) {
if (ex & 1)
ans = ans * pw % m;
pw = pw * pw % m;
ex >>= 1;
}
return ans % mod;
}
ll pw(ll a, ll n) {
ll pw = a;
ll ex = n;
ll ans = 1;
while (ex) {
if (ex & 1)
ans = ans * pw;
pw = pw * pw;
ex >>= 1;
}
return ans;
}
ll pwm(ll a, ll n) {
ll pw = a % mod;
ll ex = n;
ll ans = 1;
while (ex) {
if (ex & 1)
ans = ans * pw % mod;
pw = pw * pw % mod;
ex >>= 1;
}
return ans % mod;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v)
is >> t;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &t : v) {
os << t << " ";
}
os << '\n';
return os;
}
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// st.order_of_key(num)->number of elements < num
// st.find_by_order(i)->iterator of ith element in sorted order starting from
// zero
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll Abs(ll x) { return x > 0 ? x : (-x); }
ll Ceil(ll a, ll b) { return a / b + (a % b != 0); }
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
// #define int long long int
// Binary_Search->dp->greedy
// auto check = [&](ll x){};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char move[] = {'D', 'R', 'U', 'L'};
int X[] = {2, 1, -1, -2, -2, -1, 1, 2};
int Y[] = {1, 2, 2, 1, -1, -2, -2, -1};
struct comp {
bool operator()(const pair<int, int> &a, const pair<int, int> &b) const {
if (a.first > b.first)
return true;
if (a.first < b.first)
return false;
if (a.second < b.second)
return true;
return false;
}
};
#define N 500010
#define A 500010
#define BLOCK 750
#define M 500010
int answer;
struct query {
int l, r, ind;
} Q[M];
int ans[M], a[N], cnt[A];
void add(int index) {
cnt[a[index]]++;
if (cnt[a[index]] == 1)
answer++;
}
void remove(int index) {
cnt[a[index]]--;
if (cnt[a[index]] == 0)
answer--;
}
bool cmp(query f, query s) {
if ((f.l / BLOCK) != (s.l / BLOCK))
return (f.l / BLOCK) < (s.l / BLOCK);
return f.r < s.r;
}
void solve() {
// ifstream fin("input.txt");
// ofstream fout("output.txt");
int n, q;
scanf("%d%d", &n, &q);
rep(i, 0, n) { scanf("%d", &a[i]); }
rep(i, 0, q) {
scanf("%d%d", &Q[i].l, &Q[i].r);
Q[i].ind = i;
Q[i].l--;
Q[i].r--;
}
sort(Q, Q + q, cmp);
int cl = 0, cr = 0;
rep(i, 0, q) {
int left = Q[i].l, right = Q[i].r;
while (cl < left)
remove(cl), cl++;
while (cl > left)
add(cl - 1), cl--;
while (cr <= right)
add(cr), cr++;
while (cr > (right + 1))
remove(cr - 1), cr--;
ans[Q[i].ind] = answer;
}
rep(i, 0, q) printf("%d\n", ans[i]);
}
int32_t main() {
int t = 1;
// scanf("%d",&t);
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) \
vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end())))
#define Sort(vec) sort(vec.begin(), vec.end())
#define RSort(vec) sort(vec.rbegin(), vec.rend())
#define endl "\n"
#define tr1(i) cout << i << endl;
#define tr2(i, j) cout << i << " " << j << endl;
#define tr3(i, j, k) cout << i << " " << j << " " << k << endl;
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define all(st) st.begin(), st.end()
#define vpl vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define al vector<list<int>>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repit(st) for (auto it = st.begin(); it != st.end(); it++)
#define cs(ans) \
; \
cout << setprecision(20) << fixed << ans << endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e16)
#define inf 1e16
#define f first
#define se second
ll mod = 1e9 + 7;
using namespace std;
using namespace __gnu_pbds;
ll mi(ll n, ll m) {
ll pw = n % m;
ll ex = m - 2;
ll ans = 1;
while (ex) {
if (ex & 1)
ans = ans * pw % m;
pw = pw * pw % m;
ex >>= 1;
}
return ans % mod;
}
ll pw(ll a, ll n) {
ll pw = a;
ll ex = n;
ll ans = 1;
while (ex) {
if (ex & 1)
ans = ans * pw;
pw = pw * pw;
ex >>= 1;
}
return ans;
}
ll pwm(ll a, ll n) {
ll pw = a % mod;
ll ex = n;
ll ans = 1;
while (ex) {
if (ex & 1)
ans = ans * pw % mod;
pw = pw * pw % mod;
ex >>= 1;
}
return ans % mod;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v)
is >> t;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &t : v) {
os << t << " ";
}
os << '\n';
return os;
}
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// st.order_of_key(num)->number of elements < num
// st.find_by_order(i)->iterator of ith element in sorted order starting from
// zero
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll Abs(ll x) { return x > 0 ? x : (-x); }
ll Ceil(ll a, ll b) { return a / b + (a % b != 0); }
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
// #define int long long int
// Binary_Search->dp->greedy
// auto check = [&](ll x){};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char move[] = {'D', 'R', 'U', 'L'};
int X[] = {2, 1, -1, -2, -2, -1, 1, 2};
int Y[] = {1, 2, 2, 1, -1, -2, -2, -1};
struct comp {
bool operator()(const pair<int, int> &a, const pair<int, int> &b) const {
if (a.first > b.first)
return true;
if (a.first < b.first)
return false;
if (a.second < b.second)
return true;
return false;
}
};
#define N 500010
#define A 500010
#define BLOCK 850
#define M 500010
int answer;
struct query {
int l, r, ind;
} Q[M];
int ans[M], a[N], cnt[A];
void add(int index) {
cnt[a[index]]++;
if (cnt[a[index]] == 1)
answer++;
}
void remove(int index) {
cnt[a[index]]--;
if (cnt[a[index]] == 0)
answer--;
}
bool cmp(query f, query s) {
if ((f.l / BLOCK) != (s.l / BLOCK))
return (f.l / BLOCK) < (s.l / BLOCK);
return f.r < s.r;
}
void solve() {
// ifstream fin("input.txt");
// ofstream fout("output.txt");
int n, q;
scanf("%d%d", &n, &q);
rep(i, 0, n) { scanf("%d", &a[i]); }
rep(i, 0, q) {
scanf("%d%d", &Q[i].l, &Q[i].r);
Q[i].ind = i;
Q[i].l--;
Q[i].r--;
}
sort(Q, Q + q, cmp);
int cl = 0, cr = 0;
rep(i, 0, q) {
int left = Q[i].l, right = Q[i].r;
while (cl < left)
remove(cl), cl++;
while (cl > left)
add(cl - 1), cl--;
while (cr <= right)
add(cr), cr++;
while (cr > (right + 1))
remove(cr - 1), cr--;
ans[Q[i].ind] = answer;
}
rep(i, 0, q) printf("%d\n", ans[i]);
}
int32_t main() {
int t = 1;
// scanf("%d",&t);
while (t--) {
solve();
}
return 0;
}
| replace | 130 | 131 | 130 | 131 | TLE | |
p02599 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 30005;
const int maxq = 200005;
const int maxm = 1000005;
int n, sqr, Q;
int a[maxn];
struct query {
int l, r, lb, pos;
} q[maxq];
bool cmp(query a, query b) {
if (a.lb == b.lb)
return a.lb & 1 ? a.r > b.r : a.r < b.r;
return a.lb < b.lb;
}
int ans[maxq], num[maxm], cnt;
inline int read() {
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
inline void write(int x) {
if (x / 10)
write(x / 10);
putchar(x % 10 + '0');
}
void solve() {
int l = 1, r = 0;
for (int i = 1; i <= Q; ++i) {
while (r < q[i].r)
cnt += !num[a[++r]]++;
while (r > q[i].r)
cnt -= !--num[a[r--]];
while (l > q[i].l)
cnt += !num[a[--l]]++;
while (l < q[i].l)
cnt -= !--num[a[l++]];
ans[q[i].pos] = cnt;
}
for (int i = 1; i <= Q; ++i)
write(ans[i]), puts("");
}
int main() {
n = read();
Q = read();
for (int i = 0; i < n; ++i)
a[i] = read();
sqr = sqrt(n) + 1;
for (int i = 1; i <= Q; ++i) {
q[i].l = read();
q[i].r = read();
--q[i].l;
--q[i].r;
q[i].pos = i;
q[i].lb = q[i].l / sqr;
}
sort(q + 1, q + Q + 1, cmp);
solve();
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 500005;
const int maxq = 500005;
const int maxm = 500005;
int n, sqr, Q;
int a[maxn];
struct query {
int l, r, lb, pos;
} q[maxq];
bool cmp(query a, query b) {
if (a.lb == b.lb)
return a.lb & 1 ? a.r > b.r : a.r < b.r;
return a.lb < b.lb;
}
int ans[maxq], num[maxm], cnt;
inline int read() {
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
inline void write(int x) {
if (x / 10)
write(x / 10);
putchar(x % 10 + '0');
}
void solve() {
int l = 1, r = 0;
for (int i = 1; i <= Q; ++i) {
while (r < q[i].r)
cnt += !num[a[++r]]++;
while (r > q[i].r)
cnt -= !--num[a[r--]];
while (l > q[i].l)
cnt += !num[a[--l]]++;
while (l < q[i].l)
cnt -= !--num[a[l++]];
ans[q[i].pos] = cnt;
}
for (int i = 1; i <= Q; ++i)
write(ans[i]), puts("");
}
int main() {
n = read();
Q = read();
for (int i = 0; i < n; ++i)
a[i] = read();
sqr = sqrt(n) + 1;
for (int i = 1; i <= Q; ++i) {
q[i].l = read();
q[i].r = read();
--q[i].l;
--q[i].r;
q[i].pos = i;
q[i].lb = q[i].l / sqr;
}
sort(q + 1, q + Q + 1, cmp);
solve();
return 0;
}
| replace | 10 | 13 | 10 | 13 | 0 | |
p02599 | C++ | Runtime Error |
/*
/----- |
/ | |
| / | | |
/------ /---/ //// /---/ /--| /---/ \ / /---/ |----| |----
|---- | | | / / / / / / / | / / \ / / / | |
|____ | | | | | / \___\ / \___\ \___| \___\ \/
_____\___\ | | _____| | | |___| |
/
/
/
*/
// :::::::::::::::faraday_anshul::::::::::::::::: //
// Indian Institute Of Information Technology and Management,Gwalior. //
#include <bits/stdc++.h>
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define T() \
int t; \
cin >> t; \
while (t--)
#define rep(i, start, lim) for (int i = start; i < lim; i++)
#define repd(i, start, lim) for (int i = start; i >= lim; i--)
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define space printf(" ")
#define br printf("\n");
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(), (c).end()
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define debug cout << "here" << endl
#define TRACE
#ifdef TRACE
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#else
#define trace1(x) printf("")
#define trace2(x, y) printf("")
#define trace3(x, y, z) printf("")
#define trace4(a, b, c, d) printf("")
#define trace5(a, b, c, d, e) printf("")
#define trace6(a, b, c, d, e, f) printf("")
#endif
#define MAX 100005
#define LIMIT 262950
#define INF 1011111111
#define LLINF 1000111000111000111LL
#define EPS (double)1e-10
#define MOD 1000000007
#define PI 3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
typedef unsigned long long ulld;
lld powm(lld base, lld exp, lld mod = MOD) {
lld ans = 1;
while (exp) {
if (exp & 1)
ans = (ans * base) % mod;
exp >>= 1, base = (base * base) % mod;
}
return ans;
}
inline bool ispalin(string s) {
for (int i = 0, j = s.size() - 1; i <= j; i++, j--)
if (s[i] != s[j])
return false;
return true;
}
inline lld lcm(lld a, lld b) { return (a / __gcd(a, b)) * b; }
///******Lets start coding :-) *******//
/*
struct DSU{
lld p[MAX];
void init(lld n){
rep(i,1,n+1)p[i]=i;
}
int find(lld x){
if(p[x]==x)return x;
return p[x]=find(p[x]);
}
void join(lld x,lld y){
x=find(x);
y=find(y);
if(x==y)return;
p[y]=x;
}
}dsu;
*/
#define N 40000
#define MAXN 1000001
int a[N], pre[N], n, m, dummy[MAXN];
struct node {
int count;
node *left, *right;
node(int count, node *left, node *right)
: count(count), left(left), right(right) {}
node *insert(int l, int r, int w);
};
node *null = new node(0, NULL, NULL);
node *root[N];
node *node::insert(int l, int r, int w) {
if (l <= w and w <= r) {
if (l == r) {
return new node(this->count + 1, null, null);
}
int mid = (l + r) >> 1;
return new node(this->count + 1, this->left->insert(l, mid, w),
this->right->insert(mid + 1, r, w));
}
return this;
}
int query(node *a, int start, int end, int l, int r) {
if (end < l or start > r)
return 0;
if (start >= l and end <= r) {
return a->count;
}
int mid = (start + end) >> 1;
return query(a->left, start, mid, l, r) + query(a->right, mid + 1, end, l, r);
}
int main() {
scanf("%d %d", &n, &m);
rep(i, 1, n + 1) {
scanf("%d", &a[i]);
dummy[a[i]] = 0;
}
rep(i, 1, n + 1) {
pre[i] = dummy[a[i]];
dummy[a[i]] = i;
}
// rep(i,1,n+1)printf("%d ",pre[i]);
null->left = null->right = null;
root[0] = null;
rep(i, 1, n + 1) {
root[i] = ((i == 1) ? null : root[i - 1])->insert(0, n, pre[i]);
}
while (m--) {
int u, v;
scanf("%d%d", &u, &v);
int x = query(root[u - 1], 0, n, 0, u - 1);
int y = query(root[v], 0, n, 0, u - 1);
printf("%d\n", y - x);
}
return 0;
}
|
/*
/----- |
/ | |
| / | | |
/------ /---/ //// /---/ /--| /---/ \ / /---/ |----| |----
|---- | | | / / / / / / / | / / \ / / / | |
|____ | | | | | / \___\ / \___\ \___| \___\ \/
_____\___\ | | _____| | | |___| |
/
/
/
*/
// :::::::::::::::faraday_anshul::::::::::::::::: //
// Indian Institute Of Information Technology and Management,Gwalior. //
#include <bits/stdc++.h>
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define T() \
int t; \
cin >> t; \
while (t--)
#define rep(i, start, lim) for (int i = start; i < lim; i++)
#define repd(i, start, lim) for (int i = start; i >= lim; i--)
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define space printf(" ")
#define br printf("\n");
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(), (c).end()
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define debug cout << "here" << endl
#define TRACE
#ifdef TRACE
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#else
#define trace1(x) printf("")
#define trace2(x, y) printf("")
#define trace3(x, y, z) printf("")
#define trace4(a, b, c, d) printf("")
#define trace5(a, b, c, d, e) printf("")
#define trace6(a, b, c, d, e, f) printf("")
#endif
#define MAX 100005
#define LIMIT 262950
#define INF 1011111111
#define LLINF 1000111000111000111LL
#define EPS (double)1e-10
#define MOD 1000000007
#define PI 3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
typedef unsigned long long ulld;
lld powm(lld base, lld exp, lld mod = MOD) {
lld ans = 1;
while (exp) {
if (exp & 1)
ans = (ans * base) % mod;
exp >>= 1, base = (base * base) % mod;
}
return ans;
}
inline bool ispalin(string s) {
for (int i = 0, j = s.size() - 1; i <= j; i++, j--)
if (s[i] != s[j])
return false;
return true;
}
inline lld lcm(lld a, lld b) { return (a / __gcd(a, b)) * b; }
///******Lets start coding :-) *******//
/*
struct DSU{
lld p[MAX];
void init(lld n){
rep(i,1,n+1)p[i]=i;
}
int find(lld x){
if(p[x]==x)return x;
return p[x]=find(p[x]);
}
void join(lld x,lld y){
x=find(x);
y=find(y);
if(x==y)return;
p[y]=x;
}
}dsu;
*/
#define N 500011
#define MAXN 1000001
int a[N], pre[N], n, m, dummy[MAXN];
struct node {
int count;
node *left, *right;
node(int count, node *left, node *right)
: count(count), left(left), right(right) {}
node *insert(int l, int r, int w);
};
node *null = new node(0, NULL, NULL);
node *root[N];
node *node::insert(int l, int r, int w) {
if (l <= w and w <= r) {
if (l == r) {
return new node(this->count + 1, null, null);
}
int mid = (l + r) >> 1;
return new node(this->count + 1, this->left->insert(l, mid, w),
this->right->insert(mid + 1, r, w));
}
return this;
}
int query(node *a, int start, int end, int l, int r) {
if (end < l or start > r)
return 0;
if (start >= l and end <= r) {
return a->count;
}
int mid = (start + end) >> 1;
return query(a->left, start, mid, l, r) + query(a->right, mid + 1, end, l, r);
}
int main() {
scanf("%d %d", &n, &m);
rep(i, 1, n + 1) {
scanf("%d", &a[i]);
dummy[a[i]] = 0;
}
rep(i, 1, n + 1) {
pre[i] = dummy[a[i]];
dummy[a[i]] = i;
}
// rep(i,1,n+1)printf("%d ",pre[i]);
null->left = null->right = null;
root[0] = null;
rep(i, 1, n + 1) {
root[i] = ((i == 1) ? null : root[i - 1])->insert(0, n, pre[i]);
}
while (m--) {
int u, v;
scanf("%d%d", &u, &v);
int x = query(root[u - 1], 0, n, 0, u - 1);
int y = query(root[v], 0, n, 0, u - 1);
printf("%d\n", y - x);
}
return 0;
}
| replace | 112 | 113 | 112 | 113 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> struct BinaryIndexedTree {
vector<T> data;
BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
T sum(int k) {
T ret = 0;
for (++k; k > 0; k -= k & -k)
ret += data[k];
return (ret);
}
void add(int k, T x) {
for (++k; k < data.size(); k += k & -k)
data[k] += x;
}
};
int main() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> vp(q), in(n), pnt;
for (int i = 0; i < n; i++) {
cin >> in[i].first;
in[i].second = i;
}
sort(in.begin(), in.end());
for (int i = 0; i < n - 1; i++) {
if (in[i].first == in[i + 1].first) {
pnt.emplace_back(in[i].second, in[i + 1].second);
}
}
sort(pnt.begin(), pnt.end(),
[&](auto a, auto b) { return a.first < b.first; });
// for(auto i:pnt)cout<<i.first<<' '<<i.second<<endl;
for (int i = 0; i < q; i++)
cin >> vp[i].first >> vp[i].second, vp[i].first--, vp[i].second--;
auto oder = vp;
map<pair<int, int>, int> ans;
sort(vp.begin(), vp.end(), [&](auto a, auto b) { return a.first < b.first; });
BinaryIndexedTree<int> BIT(133333);
while (vp.size()) {
if ((!pnt.empty()) && vp.back().first <= pnt.back().first) {
BIT.add(pnt.back().second, 1);
pnt.pop_back();
} else {
auto now = vp.back();
ans[now] = 1 + now.second - now.first - BIT.sum(now.second);
vp.pop_back();
}
}
// 出力
for (int i = 0; i < q; i++)
cout << ans[oder[i]] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> struct BinaryIndexedTree {
vector<T> data;
BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
T sum(int k) {
T ret = 0;
for (++k; k > 0; k -= k & -k)
ret += data[k];
return (ret);
}
void add(int k, T x) {
for (++k; k < data.size(); k += k & -k)
data[k] += x;
}
};
int main() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> vp(q), in(n), pnt;
for (int i = 0; i < n; i++) {
cin >> in[i].first;
in[i].second = i;
}
sort(in.begin(), in.end());
for (int i = 0; i < n - 1; i++) {
if (in[i].first == in[i + 1].first) {
pnt.emplace_back(in[i].second, in[i + 1].second);
}
}
sort(pnt.begin(), pnt.end(),
[&](auto a, auto b) { return a.first < b.first; });
// for(auto i:pnt)cout<<i.first<<' '<<i.second<<endl;
for (int i = 0; i < q; i++)
cin >> vp[i].first >> vp[i].second, vp[i].first--, vp[i].second--;
auto oder = vp;
map<pair<int, int>, int> ans;
sort(vp.begin(), vp.end(), [&](auto a, auto b) { return a.first < b.first; });
BinaryIndexedTree<int> BIT(533333);
while (vp.size()) {
if ((!pnt.empty()) && vp.back().first <= pnt.back().first) {
BIT.add(pnt.back().second, 1);
pnt.pop_back();
} else {
auto now = vp.back();
ans[now] = 1 + now.second - now.first - BIT.sum(now.second);
vp.pop_back();
}
}
// 出力
for (int i = 0; i < q; i++)
cout << ans[oder[i]] << endl;
}
| replace | 44 | 45 | 44 | 45 | 0 | |
p02599 | C++ | Runtime Error | /*
ID: alec3
LANG: C++14
PROG: concom
*/
#include <bits/stdc++.h>
#define check(x) cout << (#x) << ": " << x << " ";
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
typedef unsigned long long ull;
int pct(int x) { return __builtin_popcount(x); }
using namespace std;
ifstream fin("concom.in");
ofstream fout("concom.out");
const int N = 2e6 + 1;
int n, q;
int c[N], p[N], f[N], ans[N], lz[N];
vector<pair<int, int>> qr[N];
void push(int id) {
lz[id * 2] += lz[id];
lz[id * 2 + 1] += lz[id];
lz[id] = 0;
}
void upd(int id, int l, int r, int ql, int qr, int v) {
if (l > qr || r < ql)
return;
if (ql <= l && r <= qr) {
lz[id] += v;
return;
}
push(id);
int mid = (l + r) / 2;
upd(id * 2, l, mid, ql, qr, v);
upd(id * 2 + 1, mid + 1, r, ql, qr, v);
}
int qry(int id, int l, int r, int p) {
if (l == r)
return lz[id];
push(id);
int mid = (l + r) / 2;
if (p <= mid)
return qry(id * 2, 1, mid, p);
else
return qry(id * 2 + 1, mid + 1, r, p);
}
int main() {
io;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> c[i];
p[i] = f[c[i]];
f[c[i]] = i;
}
for (int i = 1; i <= q; i++) {
int l, r;
cin >> l >> r;
qr[r].push_back({l, i});
}
for (int i = 1; i <= n; i++) {
upd(1, 1, n, p[i] + 1, i, 1);
for (auto c : qr[i]) {
ans[c.ss] = qry(1, 1, n, c.ff);
}
}
for (int i = 1; i <= q; i++) {
cout << ans[i] << endl;
}
return 0;
}
| /*
ID: alec3
LANG: C++14
PROG: concom
*/
#include <bits/stdc++.h>
#define check(x) cout << (#x) << ": " << x << " ";
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
typedef unsigned long long ull;
int pct(int x) { return __builtin_popcount(x); }
using namespace std;
ifstream fin("concom.in");
ofstream fout("concom.out");
const int N = 2e6 + 1;
int n, q;
int c[N], p[N], f[N], ans[N], lz[N];
vector<pair<int, int>> qr[N];
void push(int id) {
lz[id * 2] += lz[id];
lz[id * 2 + 1] += lz[id];
lz[id] = 0;
}
void upd(int id, int l, int r, int ql, int qr, int v) {
if (l > qr || r < ql)
return;
if (ql <= l && r <= qr) {
lz[id] += v;
return;
}
push(id);
int mid = (l + r) / 2;
upd(id * 2, l, mid, ql, qr, v);
upd(id * 2 + 1, mid + 1, r, ql, qr, v);
}
int qry(int id, int l, int r, int p) {
if (l == r)
return lz[id];
push(id);
int mid = (l + r) / 2;
if (p <= mid)
return qry(id * 2, l, mid, p);
else
return qry(id * 2 + 1, mid + 1, r, p);
}
int main() {
io;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> c[i];
p[i] = f[c[i]];
f[c[i]] = i;
}
for (int i = 1; i <= q; i++) {
int l, r;
cin >> l >> r;
qr[r].push_back({l, i});
}
for (int i = 1; i <= n; i++) {
upd(1, 1, n, p[i] + 1, i, 1);
for (auto c : qr[i]) {
ans[c.ss] = qry(1, 1, n, c.ff);
}
}
for (int i = 1; i <= q; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct _IO {
_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
}
} _io;
typedef long long ll;
typedef long double db;
const int N = 3e5 + 5, M = 1e9 + 7;
typedef pair<int, int> pii;
#define fi first
#define se second
int bit[N];
void add(int p, int v) {
for (; p < N; p += p & -p)
bit[p] += v;
}
int get(int p) {
int res = 0;
for (; p; p -= p & -p)
res += bit[p];
return res;
}
vector<pii> q[N];
int ans[N], lst[N], a[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int l, r;
for (int i = 1; i <= m; i++) {
cin >> l >> r;
q[r].push_back({l, i});
}
for (int i = 1; i <= n; i++) {
if (lst[a[i]])
add(lst[a[i]], -1);
add(i, 1);
lst[a[i]] = i;
for (auto &p : q[i]) {
ans[p.se] = get(i) - get(p.fi - 1);
}
}
for (int i = 1; i <= m; i++) {
cout << ans[i] << '\n';
}
}
| #include <bits/stdc++.h>
using namespace std;
struct _IO {
_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
}
} _io;
typedef long long ll;
typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;
typedef pair<int, int> pii;
#define fi first
#define se second
int bit[N];
void add(int p, int v) {
for (; p < N; p += p & -p)
bit[p] += v;
}
int get(int p) {
int res = 0;
for (; p; p -= p & -p)
res += bit[p];
return res;
}
vector<pii> q[N];
int ans[N], lst[N], a[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int l, r;
for (int i = 1; i <= m; i++) {
cin >> l >> r;
q[r].push_back({l, i});
}
for (int i = 1; i <= n; i++) {
if (lst[a[i]])
add(lst[a[i]], -1);
add(i, 1);
lst[a[i]] = i;
for (auto &p : q[i]) {
ans[p.se] = get(i) - get(p.fi - 1);
}
}
for (int i = 1; i <= m; i++) {
cout << ans[i] << '\n';
}
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02599 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
const int MAXN = 3e4 + 5;
const int M = MAXN * 100;
int n, q, tot;
int a[MAXN];
int T[MAXN], lson[M], rson[M], c[M];
int build(int l, int r) {
int root = tot++;
c[root] = 0;
if (l != r) {
int mid = (l + r) >> 1;
lson[root] = build(l, mid);
rson[root] = build(mid + 1, r);
}
return root;
}
int update(int root, int pos, int val) {
int newroot = tot++, tmp = newroot;
c[newroot] = c[root] + val;
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (pos <= mid) {
lson[newroot] = tot++;
rson[newroot] = rson[root];
newroot = lson[newroot];
root = lson[root];
r = mid;
} else {
rson[newroot] = tot++;
lson[newroot] = lson[root];
newroot = rson[newroot];
root = rson[root];
l = mid + 1;
}
c[newroot] = c[root] + val;
}
return tmp;
}
int query(int root, int pos) {
int ret = 0;
int l = 1, r = n;
while (pos < r) {
int mid = (l + r) >> 1;
if (pos <= mid) {
r = mid;
root = lson[root];
} else {
ret += c[lson[root]];
root = rson[root];
l = mid + 1;
}
}
return ret + c[root];
}
int main() {
tot = 0;
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
T[n + 1] = build(1, n);
map<int, int> mp;
for (int i = n; i >= 1; i--) {
if (mp.find(a[i]) == mp.end()) {
T[i] = update(T[i + 1], i, 1);
} else {
int tmp = update(T[i + 1], mp[a[i]], -1);
T[i] = update(tmp, i, 1);
}
mp[a[i]] = i;
}
while (q--) {
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", query(T[l], r));
}
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
const int MAXN = 5e5 + 5;
const int M = MAXN * 100;
int n, q, tot;
int a[MAXN];
int T[MAXN], lson[M], rson[M], c[M];
int build(int l, int r) {
int root = tot++;
c[root] = 0;
if (l != r) {
int mid = (l + r) >> 1;
lson[root] = build(l, mid);
rson[root] = build(mid + 1, r);
}
return root;
}
int update(int root, int pos, int val) {
int newroot = tot++, tmp = newroot;
c[newroot] = c[root] + val;
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (pos <= mid) {
lson[newroot] = tot++;
rson[newroot] = rson[root];
newroot = lson[newroot];
root = lson[root];
r = mid;
} else {
rson[newroot] = tot++;
lson[newroot] = lson[root];
newroot = rson[newroot];
root = rson[root];
l = mid + 1;
}
c[newroot] = c[root] + val;
}
return tmp;
}
int query(int root, int pos) {
int ret = 0;
int l = 1, r = n;
while (pos < r) {
int mid = (l + r) >> 1;
if (pos <= mid) {
r = mid;
root = lson[root];
} else {
ret += c[lson[root]];
root = rson[root];
l = mid + 1;
}
}
return ret + c[root];
}
int main() {
tot = 0;
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
T[n + 1] = build(1, n);
map<int, int> mp;
for (int i = n; i >= 1; i--) {
if (mp.find(a[i]) == mp.end()) {
T[i] = update(T[i + 1], i, 1);
} else {
int tmp = update(T[i + 1], mp[a[i]], -1);
T[i] = update(tmp, i, 1);
}
mp[a[i]] = i;
}
while (q--) {
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", query(T[l], r));
}
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02599 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(a) a.begin(), a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> class segtree {
int n;
vector<T> data;
T id = 0;
T operation(T a, T b) { return a + b; };
public:
segtree(int _n) {
n = 1;
while (n < _n + 2)
n <<= 1;
data = vector<T>(2 * n, id);
}
void change(int i, T x) {
i += n;
data[i] = x;
while (i > 1) {
i >>= 1;
data[i] = operation(data[i << 1], data[i << 1 | 1]);
}
}
void add(int i, T x) { change(i, data[i + n] + x); }
T get(int a, int b) {
T left = id;
T right = id;
a += n;
b += n;
while (a < b) {
if (a & 1)
left = operation(left, data[a++]);
if (b & 1)
right = operation(data[--b], right);
a >>= 1;
b >>= 1;
}
return operation(left, right);
}
T get_all() { return data[1]; }
T operator[](int i) { return data[i + n]; }
};
bool comp(pair<P, int> a, pair<P, int> b) {
return a.first.second < b.first.second;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, q;
cin >> n >> q;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
a[i]--;
}
vector<pair<P, int>> p(q);
rep(i, q) {
cin >> p[i].first.first >> p[i].first.second;
p[i].first.first--;
p[i].first.second--;
p[i].second = i;
}
sort(all(p), comp);
vector<int> lst(n, -1);
segtree<int> seg(n);
vector<P> ans(q);
int prev = -1;
rep(i, q) {
int pf = p[i].first.first;
int ps = p[i].first.second;
for (int j = prev + 1; j <= ps; j++) {
if (lst[a[j]] != -1)
seg.add(lst[a[j]], -1);
seg.add(j, 1);
lst[a[j]] = j;
}
ans[i].second = seg.get(pf, ps + 1);
}
rep(i, q) ans[i].first = p[i].second;
sort(all(ans));
for (auto i : ans)
cout << i.second << '\n';
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(a) a.begin(), a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> class segtree {
int n;
vector<T> data;
T id = 0;
T operation(T a, T b) { return a + b; };
public:
segtree(int _n) {
n = 1;
while (n < _n + 2)
n <<= 1;
data = vector<T>(2 * n, id);
}
void change(int i, T x) {
i += n;
data[i] = x;
while (i > 1) {
i >>= 1;
data[i] = operation(data[i << 1], data[i << 1 | 1]);
}
}
void add(int i, T x) { change(i, data[i + n] + x); }
T get(int a, int b) {
T left = id;
T right = id;
a += n;
b += n;
while (a < b) {
if (a & 1)
left = operation(left, data[a++]);
if (b & 1)
right = operation(data[--b], right);
a >>= 1;
b >>= 1;
}
return operation(left, right);
}
T get_all() { return data[1]; }
T operator[](int i) { return data[i + n]; }
};
bool comp(pair<P, int> a, pair<P, int> b) {
return a.first.second < b.first.second;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, q;
cin >> n >> q;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
a[i]--;
}
vector<pair<P, int>> p(q);
rep(i, q) {
cin >> p[i].first.first >> p[i].first.second;
p[i].first.first--;
p[i].first.second--;
p[i].second = i;
}
sort(all(p), comp);
vector<int> lst(n, -1);
segtree<int> seg(n);
vector<P> ans(q);
int prev = -1;
rep(i, q) {
int pf = p[i].first.first;
int ps = p[i].first.second;
for (int j = prev + 1; j <= ps; j++) {
if (lst[a[j]] != -1)
seg.add(lst[a[j]], -1);
seg.add(j, 1);
lst[a[j]] = j;
}
ans[i].second = seg.get(pf, ps + 1);
prev = ps;
}
rep(i, q) ans[i].first = p[i].second;
sort(all(ans));
for (auto i : ans)
cout << i.second << '\n';
} | insert | 132 | 132 | 132 | 133 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x) cerr << #x << ": " << x << endl;
#define rep(i, a) for (ll i = 0; i < a; i++)
#define pb push_back
#define vl vector<ll>
const ll N = 1e5 + 5;
vector<ll> tree(4 * N);
void update(ll cur, ll l, ll r, ll pos) {
if (l > pos || r < pos)
return;
if (l == r && r == pos) {
tree[cur] = 1;
return;
}
ll m = (r + l) / 2;
update(2 * cur, l, m, pos);
update(2 * cur + 1, m + 1, r, pos);
tree[cur] = tree[2 * cur] + tree[2 * cur + 1];
}
ll sum(ll i, ll l, ll r, ll x, ll y) {
if (l > y || r < x)
return 0;
if (x <= l && r <= y)
return tree[i];
ll m = (r + l) / 2;
return sum(2 * i, l, m, x, y) + sum(2 * i + 1, m + 1, r, x, y);
}
bool comp(pair<pair<ll, ll>, ll> a, pair<pair<ll, ll>, ll> b) {
return a.first.second < b.first.second;
}
int main() {
fast;
ll n;
cin >> n;
ll q;
cin >> q;
vector<ll> a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
vector<ll> nxt(n);
map<ll, ll> occ;
vector<pair<ll, ll>> toup;
for (ll i = n - 1; i >= 0; i--) {
if (occ.count(a[i]) == 0)
nxt[i] = n + 1;
else
nxt[i] = occ[a[i]];
occ[a[i]] = i;
toup.push_back({nxt[i], i});
}
vector<pair<pair<ll, ll>, ll>> query;
for (ll i = 0; i < q; i++) {
ll l, r;
cin >> l >> r;
l--;
r--;
query.push_back({{l, r}, i});
}
sort(query.begin(), query.end(), comp);
reverse(query.begin(), query.end());
sort(toup.begin(), toup.end());
reverse(toup.begin(), toup.end());
vector<ll> ans(q);
ll j = 0;
for (ll i = 0; i < q; i++) {
while (j < n && toup[j].first > query[i].first.second)
update(1, 0, n - 1, toup[j++].second);
ans[query[i].second] =
sum(1, 0, n - 1, query[i].first.first, query[i].first.second);
}
for (ll i = 0; i < q; i++)
cout << ans[i] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x) cerr << #x << ": " << x << endl;
#define rep(i, a) for (ll i = 0; i < a; i++)
#define pb push_back
#define vl vector<ll>
const ll N = 5 * 1e5 + 5;
vector<ll> tree(4 * N);
void update(ll cur, ll l, ll r, ll pos) {
if (l > pos || r < pos)
return;
if (l == r && r == pos) {
tree[cur] = 1;
return;
}
ll m = (r + l) / 2;
update(2 * cur, l, m, pos);
update(2 * cur + 1, m + 1, r, pos);
tree[cur] = tree[2 * cur] + tree[2 * cur + 1];
}
ll sum(ll i, ll l, ll r, ll x, ll y) {
if (l > y || r < x)
return 0;
if (x <= l && r <= y)
return tree[i];
ll m = (r + l) / 2;
return sum(2 * i, l, m, x, y) + sum(2 * i + 1, m + 1, r, x, y);
}
bool comp(pair<pair<ll, ll>, ll> a, pair<pair<ll, ll>, ll> b) {
return a.first.second < b.first.second;
}
int main() {
fast;
ll n;
cin >> n;
ll q;
cin >> q;
vector<ll> a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
vector<ll> nxt(n);
map<ll, ll> occ;
vector<pair<ll, ll>> toup;
for (ll i = n - 1; i >= 0; i--) {
if (occ.count(a[i]) == 0)
nxt[i] = n + 1;
else
nxt[i] = occ[a[i]];
occ[a[i]] = i;
toup.push_back({nxt[i], i});
}
vector<pair<pair<ll, ll>, ll>> query;
for (ll i = 0; i < q; i++) {
ll l, r;
cin >> l >> r;
l--;
r--;
query.push_back({{l, r}, i});
}
sort(query.begin(), query.end(), comp);
reverse(query.begin(), query.end());
sort(toup.begin(), toup.end());
reverse(toup.begin(), toup.end());
vector<ll> ans(q);
ll j = 0;
for (ll i = 0; i < q; i++) {
while (j < n && toup[j].first > query[i].first.second)
update(1, 0, n - 1, toup[j++].second);
ans[query[i].second] =
sum(1, 0, n - 1, query[i].first.first, query[i].first.second);
}
for (ll i = 0; i < q; i++)
cout << ans[i] << "\n";
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
constexpr int B = 400;
struct Q {
int L, R, id;
bool operator<(const Q &o) const { return pii{L / B, R} < pii{o.L / B, o.R}; }
};
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int n, nq;
cin >> n >> nq;
map<int, vi> f;
rep(i, 0, n) {
int a;
cin >> a;
f[a].push_back(i);
}
vi x(n);
int k = 0;
trav(p, f) {
trav(i, p.second) x[i] = k;
k++;
}
vi cnt(k);
vector<Q> q(nq);
rep(i, 0, nq) {
cin >> q[i].L >> q[i].R;
q[i].L--, q[i].R--;
q[i].id = i;
}
sort(all(q));
int L = 0, R = -1, dc = 0;
vi qans(nq);
auto add = [&](int i) {
if (++cnt[i] == 1)
dc++;
};
auto rem = [&](int i) {
if (--cnt[i] == 0)
dc--;
};
trav(cq, q) {
while (L < cq.L)
rem(x[L++]);
while (L > cq.L)
add(x[--L]);
while (R < cq.R)
add(x[++R]);
while (R > cq.R)
rem(x[R--]);
qans[cq.id] = dc;
}
trav(i, qans) cout << i << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
constexpr int B = 900;
struct Q {
int L, R, id;
bool operator<(const Q &o) const { return pii{L / B, R} < pii{o.L / B, o.R}; }
};
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int n, nq;
cin >> n >> nq;
map<int, vi> f;
rep(i, 0, n) {
int a;
cin >> a;
f[a].push_back(i);
}
vi x(n);
int k = 0;
trav(p, f) {
trav(i, p.second) x[i] = k;
k++;
}
vi cnt(k);
vector<Q> q(nq);
rep(i, 0, nq) {
cin >> q[i].L >> q[i].R;
q[i].L--, q[i].R--;
q[i].id = i;
}
sort(all(q));
int L = 0, R = -1, dc = 0;
vi qans(nq);
auto add = [&](int i) {
if (++cnt[i] == 1)
dc++;
};
auto rem = [&](int i) {
if (--cnt[i] == 0)
dc--;
};
trav(cq, q) {
while (L < cq.L)
rem(x[L++]);
while (L > cq.L)
add(x[--L]);
while (R < cq.R)
add(x[++R]);
while (R > cq.R)
rem(x[R--]);
qans[cq.id] = dc;
}
trav(i, qans) cout << i << '\n';
return 0;
} | replace | 11 | 12 | 11 | 12 | TLE | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FASTINOUT \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
const int N = 5e5 + 9;
int a[N], Block, value, m[N];
bool ok[N];
struct query {
int l, r, i;
};
query q[N];
bool f(query q1, query q2) {
if (q1.l / Block != q2.l / Block)
return q1.l / Block < q2.l / Block;
return q1.r < q2.r;
}
void add(int pos) {
int val = a[pos];
m[val]++;
if (m[val] == 1) {
value++;
} else if (!m[val]) {
value--;
}
}
void remove(int pos) {
int val = a[pos];
m[val]--;
if (!m[val]) {
value--;
}
}
int main() {
FASTINOUT;
int x, t;
scanf("%d%d", &x, &t);
Block = sqrtl(x);
for (int i = 0; i < x; i++)
scanf("%d", &a[i]);
for (int j = 0; j < t; j++) {
scanf("%d%d", &q[j].l, &q[j].r);
q[j].l--;
q[j].r--;
q[j].i = j;
}
sort(q, q + t, f);
int start = 0, end = -1;
vector<int> ans(t);
for (int i = 0; i < t; i++) {
int L = q[i].l, R = q[i].r;
while (start > L)
start--, add(start);
while (end < R)
end++, add(end);
while (start < L)
remove(start), start++;
while (end > R)
remove(end), end--;
ans[q[i].i] = value;
}
for (int j : ans)
printf("%d\n", j);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FASTINOUT \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
const int N = 5e5 + 9;
int a[N], Block, value, m[N];
bool ok[N];
struct query {
int l, r, i;
};
query q[N];
bool f(query a, query b) {
if (a.l / Block != b.l / Block)
return a.l < b.l;
return a.l / Block % 2 ? a.r < b.r : a.r > b.r;
}
void add(int pos) {
int val = a[pos];
m[val]++;
if (m[val] == 1) {
value++;
} else if (!m[val]) {
value--;
}
}
void remove(int pos) {
int val = a[pos];
m[val]--;
if (!m[val]) {
value--;
}
}
int main() {
FASTINOUT;
int x, t;
scanf("%d%d", &x, &t);
Block = sqrtl(x);
for (int i = 0; i < x; i++)
scanf("%d", &a[i]);
for (int j = 0; j < t; j++) {
scanf("%d%d", &q[j].l, &q[j].r);
q[j].l--;
q[j].r--;
q[j].i = j;
}
sort(q, q + t, f);
int start = 0, end = -1;
vector<int> ans(t);
for (int i = 0; i < t; i++) {
int L = q[i].l, R = q[i].r;
while (start > L)
start--, add(start);
while (end < R)
end++, add(end);
while (start < L)
remove(start), start++;
while (end > R)
remove(end), end--;
ans[q[i].i] = value;
}
for (int j : ans)
printf("%d\n", j);
return 0;
}
| replace | 15 | 20 | 15 | 19 | TLE | |
p02599 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define left 2 * node + 1
#define right left + 1
#define mid (s + e >> 1)
const ll N = 5e5 + 5;
vector<ll> T[4 * N];
void build(ll A[], ll node, ll s, ll e) {
if (s == e) {
T[node].push_back(A[s]);
return;
}
build(A, left, s, mid);
build(A, right, mid + 1, e);
merge(T[left].begin(), T[left].end(), T[right].begin(), T[right].end(),
back_inserter(T[node]));
}
ll query(ll node, ll s, ll e, ll x, ll y) {
if (e < s || s > y || e < x)
return 0;
if (x <= s && e <= y) {
ll a = upper_bound(T[node].begin(), T[node].end(), y) - T[node].begin();
return T[node].size() - a;
}
ll p1 = query(left, s, mid, x, y);
ll p2 = query(right, 1 + mid, e, x, y);
return p1 + p2;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, q;
cin >> n >> q;
ll A[n];
ll B[n];
for (ll i = 0; i < n; i++)
cin >> A[i];
map<ll, ll> M;
for (ll i = n - 1; i >= 0; i--) {
if (M.count(A[i]))
B[i] = M[A[i]];
else
B[i] = INT_MAX;
M[A[i]] = i;
}
build(B, 0, 0, n - 1);
while (q--) {
ll x, y;
cin >> x >> y;
ll ans = query(0, 0, n - 1, x - 1, y - 1);
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define left 2 * node + 1
#define right left + 1
#define mid (s + e >> 1)
const ll N = 5e5 + 5;
vector<ll> T[4 * N];
void build(ll A[], ll node, ll s, ll e) {
if (s == e) {
T[node].push_back(A[s]);
return;
}
build(A, left, s, mid);
build(A, right, mid + 1, e);
merge(T[left].begin(), T[left].end(), T[right].begin(), T[right].end(),
back_inserter(T[node]));
}
ll query(ll node, ll s, ll e, ll x, ll y) {
if (e < s || s > y || e < x)
return 0;
if (x <= s && e <= y) {
ll a = upper_bound(T[node].begin(), T[node].end(), y) - T[node].begin();
return T[node].size() - a;
}
ll p1 = query(left, s, mid, x, y);
ll p2 = query(right, 1 + mid, e, x, y);
return p1 + p2;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, q;
cin >> n >> q;
ll A[n];
ll B[n];
for (ll i = 0; i < n; i++)
cin >> A[i];
map<ll, ll> M;
for (ll i = n - 1; i >= 0; i--) {
if (M.count(A[i]))
B[i] = M[A[i]];
else
B[i] = INT_MAX;
M[A[i]] = i;
}
build(B, 0, 0, n - 1);
while (q--) {
ll x, y;
cin >> x >> y;
ll ans = query(0, 0, n - 1, x - 1, y - 1);
cout << ans << "\n";
}
}
| replace | 63 | 64 | 63 | 64 | TLE | |
p02599 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
const int MAX_NODE_CNT = MAXN << 5;
int n, m, lst[MAXN];
struct Persistent_Segment_Tree {
#define mid ((l + r) >> 1)
#define ls(_) t[_].ls
#define rs(_) t[_].rs
#define lq(_) t[_].ls, l, mid
#define rq(_) t[_].rs, mid + 1, r
int node_cnt, rt[MAXN];
int &operator[](const int &x) { return rt[x]; }
struct node {
int ls, rs, data;
} t[MAX_NODE_CNT];
int build(int l, int r) {
int cur = ++node_cnt;
if (l == r)
return cur;
ls(cur) = build(l, mid), rs(cur) = build(mid + 1, r);
return cur;
}
int modify(int pre, int l, int r, int pos, int val) {
int cur = ++node_cnt;
t[cur] = t[pre], t[cur].data += val;
if (l == r) {
return cur;
}
if (pos <= mid)
ls(cur) = modify(ls(pre), l, mid, pos, val);
else
rs(cur) = modify(rs(pre), mid + 1, r, pos, val);
return cur;
}
int query(int cur, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return t[cur].data;
int ret = 0;
if (ql <= mid)
ret += query(lq(cur), ql, qr);
if (qr > mid)
ret += query(rq(cur), ql, qr);
return ret;
}
} t;
int main() {
scanf("%d %d", &n, &m);
t[0] = t.build(1, n);
for (int i = 1, x; i <= n; ++i) {
scanf("%d", &x);
t[i] = t.modify(t[i - 1], 1, n, i, 1);
if (lst[x])
t[i] = t.modify(t[i], 1, n, lst[x], -1);
lst[x] = i;
}
int pre_ans = 0;
for (int i = 1, u, v; i <= m; ++i) {
scanf("%d %d", &u, &v);
printf("%d\n", (t.query(t[v], 1, n, u, v)));
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
const int MAX_NODE_CNT = MAXN << 6;
int n, m, lst[MAXN];
struct Persistent_Segment_Tree {
#define mid ((l + r) >> 1)
#define ls(_) t[_].ls
#define rs(_) t[_].rs
#define lq(_) t[_].ls, l, mid
#define rq(_) t[_].rs, mid + 1, r
int node_cnt, rt[MAXN];
int &operator[](const int &x) { return rt[x]; }
struct node {
int ls, rs, data;
} t[MAX_NODE_CNT];
int build(int l, int r) {
int cur = ++node_cnt;
if (l == r)
return cur;
ls(cur) = build(l, mid), rs(cur) = build(mid + 1, r);
return cur;
}
int modify(int pre, int l, int r, int pos, int val) {
int cur = ++node_cnt;
t[cur] = t[pre], t[cur].data += val;
if (l == r) {
return cur;
}
if (pos <= mid)
ls(cur) = modify(ls(pre), l, mid, pos, val);
else
rs(cur) = modify(rs(pre), mid + 1, r, pos, val);
return cur;
}
int query(int cur, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return t[cur].data;
int ret = 0;
if (ql <= mid)
ret += query(lq(cur), ql, qr);
if (qr > mid)
ret += query(rq(cur), ql, qr);
return ret;
}
} t;
int main() {
scanf("%d %d", &n, &m);
t[0] = t.build(1, n);
for (int i = 1, x; i <= n; ++i) {
scanf("%d", &x);
t[i] = t.modify(t[i - 1], 1, n, i, 1);
if (lst[x])
t[i] = t.modify(t[i], 1, n, lst[x], -1);
lst[x] = i;
}
int pre_ans = 0;
for (int i = 1, u, v; i <= m; ++i) {
scanf("%d %d", &u, &v);
printf("%d\n", (t.query(t[v], 1, n, u, v)));
}
return 0;
} | replace | 4 | 5 | 4 | 5 | -11 | |
p02600 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 1111LL
#define cout1(x) cout << x << "\n";
#define deb(x) cout << #x << " " << x << "\n";
#define vii vector<pa>;
using namespace std;
#define MAXN 1000000ll
// template<typename... T>
// void read(T&... args){
// ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
// ((cout<<args<<"\n"), ...);
// }
v visited(N);
vector<ll> ans = {-1};
v level(N);
v ind(N);
ll sz[N];
// void dfs(ll node, ll par){
// visited[node]=1;
// if (node==1)level[1]=0;
// else level[node] = level[par]+1;
// ans.pb(node);
// for(auto x:graph[node]){
// if (!visited[x]){
// dfs(x,node);
// sz[node]+=sz[x];
// }
// }
// ++sz[node];
// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
// cout<<ans<<" "<<x<<endl;
// if (cnt[ans%x]==0)return ans;
// else if (cnt[ans%x==1] && ans>x)return ans;
// else{
// cnt[ans%x]-=1;
// cnt[ans]+=1;
// answer(ans+1,x);
// }
// }
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
ll power(ll x, unsigned ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
auto primeFactors(ll n) {
map<ll, ll> fact;
// Print the number of 2s that divide n
while (n % 2 == 0) {
fact[2] += 1;
n = n / 2;
}
for (ll i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
fact[i] += 1;
n = n / i;
}
}
if (n > 2)
fact[n] += 1;
return fact;
}
auto getFactorization(int x) {
map<ll, ll> ret;
;
while (x != 1) {
ret[spf[x]] += 1;
x = x / spf[x];
}
return ret;
}
ll solve() {
ll x;
cin >> x;
if (x >= 400 && x <= 599)
cout1(8);
if (x >= 600 && x <= 799)
cout1(7);
if (x >= 800 && x <= 999)
cout1(6);
if (x >= 1000 && x <= 1199)
cout1(5);
if (x >= 1200 && x <= 1399)
cout1(4);
if (x >= 1400 && x <= 1599)
cout1(3);
if (x >= 1600 && x <= 1799)
cout1(2);
if (x >= 1800 && x <= 1999)
cout1(1);
}
int main() {
fastio;
ll tests = 1;
// cin>>tests;
while (tests--)
solve();
}
| #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 1111LL
#define cout1(x) cout << x << "\n";
#define deb(x) cout << #x << " " << x << "\n";
#define vii vector<pa>;
using namespace std;
#define MAXN 1000000ll
// template<typename... T>
// void read(T&... args){
// ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
// ((cout<<args<<"\n"), ...);
// }
v visited(N);
vector<ll> ans = {-1};
v level(N);
v ind(N);
ll sz[N];
// void dfs(ll node, ll par){
// visited[node]=1;
// if (node==1)level[1]=0;
// else level[node] = level[par]+1;
// ans.pb(node);
// for(auto x:graph[node]){
// if (!visited[x]){
// dfs(x,node);
// sz[node]+=sz[x];
// }
// }
// ++sz[node];
// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
// cout<<ans<<" "<<x<<endl;
// if (cnt[ans%x]==0)return ans;
// else if (cnt[ans%x==1] && ans>x)return ans;
// else{
// cnt[ans%x]-=1;
// cnt[ans]+=1;
// answer(ans+1,x);
// }
// }
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
ll power(ll x, unsigned ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
auto primeFactors(ll n) {
map<ll, ll> fact;
// Print the number of 2s that divide n
while (n % 2 == 0) {
fact[2] += 1;
n = n / 2;
}
for (ll i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
fact[i] += 1;
n = n / i;
}
}
if (n > 2)
fact[n] += 1;
return fact;
}
auto getFactorization(int x) {
map<ll, ll> ret;
;
while (x != 1) {
ret[spf[x]] += 1;
x = x / spf[x];
}
return ret;
}
void solve() {
ll x;
cin >> x;
if (x >= 400 && x <= 599)
cout1(8);
if (x >= 600 && x <= 799)
cout1(7);
if (x >= 800 && x <= 999)
cout1(6);
if (x >= 1000 && x <= 1199)
cout1(5);
if (x >= 1200 && x <= 1399)
cout1(4);
if (x >= 1400 && x <= 1599)
cout1(3);
if (x >= 1600 && x <= 1799)
cout1(2);
if (x >= 1800 && x <= 1999)
cout1(1);
}
int main() {
fastio;
ll tests = 1;
// cin>>tests;
while (tests--)
solve();
}
| replace | 150 | 151 | 150 | 151 | TLE | |
p02600 | C++ | Runtime Error | #include <stdio.h>
int main() {
int n;
scanf("%d", n);
if (n <= 1999 && n >= 1800) {
printf("1");
} else if (n <= 1799 && n >= 1600) {
printf("2");
} else if (n <= 1599 && n >= 1400) {
printf("3");
} else if (n <= 1399 && n >= 1200) {
printf("4");
} else if (n <= 1199 && n >= 1000) {
printf("5");
} else if (n <= 999 && n >= 800) {
printf("6");
} else if (n <= 799 && n >= 600) {
printf("7");
} else if (n <= 599 && n >= 400) {
printf("8");
}
return 0;
} | #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n <= 1999 && n >= 1800) {
printf("1");
} else if (n <= 1799 && n >= 1600) {
printf("2");
} else if (n <= 1599 && n >= 1400) {
printf("3");
} else if (n <= 1399 && n >= 1200) {
printf("4");
} else if (n <= 1199 && n >= 1000) {
printf("5");
} else if (n <= 999 && n >= 800) {
printf("6");
} else if (n <= 799 && n >= 600) {
printf("7");
} else if (n <= 599 && n >= 400) {
printf("8");
}
return 0;
} | replace | 3 | 4 | 3 | 4 | -11 | |
p02600 | C++ | Runtime Error | #include <cassert>
#include <iostream>
#include <stdexcept>
using namespace std;
int main() {
int X;
cin >> X;
assert(400 <= X && X <= 1999);
int kyu;
if (X < 600)
kyu = 8;
else if (X < 800)
kyu = 7;
else if (X < 1000)
kyu = 6;
else if (X < 1200)
kyu = 5;
else if (X < 1400)
kyu = 4;
else if (X < 1600)
kyu = 3;
else if (X < 1800)
kyu = 2;
else if (X < 200)
kyu = 1;
else
throw runtime_error("what's?");
cout << kyu << endl;
return 0;
}
| #include <cassert>
#include <iostream>
#include <stdexcept>
using namespace std;
int main() {
int X;
cin >> X;
assert(400 <= X && X <= 1999);
int kyu;
if (X < 600)
kyu = 8;
else if (X < 800)
kyu = 7;
else if (X < 1000)
kyu = 6;
else if (X < 1200)
kyu = 5;
else if (X < 1400)
kyu = 4;
else if (X < 1600)
kyu = 3;
else if (X < 1800)
kyu = 2;
else if (X < 2000)
kyu = 1;
else
throw runtime_error("what's?");
cout << kyu << endl;
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02600 | Python | Runtime Error | X = int(input())
if 400 <= X < 600:
result = 8
elif X < 800:
result = 7
elif X < 1000:
result = 6
elif X < 1200:
result = 5
elif X < 1400:
result = 4
elif X < 1600:
result = 3
elif X < 1800:
result = 2
elif X < 200:
result = 1
print(result)
| X = int(input())
if 400 <= X < 600:
result = 8
elif X < 800:
result = 7
elif X < 1000:
result = 6
elif X < 1200:
result = 5
elif X < 1400:
result = 4
elif X < 1600:
result = 3
elif X < 1800:
result = 2
elif X < 2000:
result = 1
print(result)
| replace | 16 | 17 | 16 | 17 | 0 | |
p02601 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int A, B, C, K;
bool flag = false;
for (int i = 0; i <= K; ++i) {
for (int j = 0; j <= K; ++j) {
for (int l = 0; l <= K; ++l) {
int x = A * (1 << i), y = B * (1 << j), z = C * (1 << l);
if (x < y && y < z && i + j + l <= K)
flag = true;
}
}
}
if (flag == true)
cout << "Yes";
else
cout << "No";
} | #include <iostream>
using namespace std;
int main() {
int A, B, C, K;
bool flag = false;
cin >> A >> B >> C >> K;
for (int i = 0; i <= K; ++i) {
for (int j = 0; j <= K; ++j) {
for (int l = 0; l <= K; ++l) {
int x = A * (1 << i), y = B * (1 << j), z = C * (1 << l);
if (x < y && y < z && i + j + l <= K)
flag = true;
}
}
}
if (flag == true)
cout << "Yes";
else
cout << "No";
} | replace | 7 | 8 | 7 | 8 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;
inline void quickread() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
inline void work() {
int a, b, c, k;
cin >> a >> b >> c >> k;
// c > b > a
while (k) {
if (b <= a) {
b *= 2;
k--;
} else if (c <= b) {
c *= 2;
k--;
}
}
if (c > b && b > a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
// freopen(".txt", "r", stdin);
quickread();
work();
return 0;
} | #include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;
inline void quickread() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
inline void work() {
int a, b, c, k;
cin >> a >> b >> c >> k;
// c > b > a
while (k) {
if (b <= a) {
b *= 2;
k--;
} else if (c <= b) {
c *= 2;
k--;
} else
break;
}
if (c > b && b > a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
// freopen(".txt", "r", stdin);
quickread();
work();
return 0;
} | replace | 45 | 46 | 45 | 47 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K;
cin >> A >> B >> C;
cin >> K;
while (K > 0) {
if (B <= A) {
B *= 2;
K--;
} else if (C <= B) {
C *= 2;
K--;
}
}
if (B > A && C > B) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K;
cin >> A >> B >> C;
cin >> K;
while (K > 0) {
if (B > A && C > B) {
break;
}
if (B <= A) {
B *= 2;
K--;
} else if (C <= B) {
C *= 2;
K--;
}
}
if (B > A && C > B) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| insert | 9 | 9 | 9 | 13 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int A, B, C, K;
cin >> A >> B >> C;
cin >> K;
int count = 0;
while (count < K) {
if (B <= A) {
B = B * 2;
count++;
} else if (count < K && C <= B) {
C = C * 2;
count++;
}
}
if (B > A && C > B)
printf("Yes\n");
else
printf("No\n");
return 0;
} | #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int A, B, C, K;
cin >> A >> B >> C;
cin >> K;
int count = 0;
while (count < K && !(B > A && C > B)) {
if (B <= A) {
B = B * 2;
count++;
} else if (count < K && C <= B) {
C = C * 2;
count++;
}
}
if (B > A && C > B)
printf("Yes\n");
else
printf("No\n");
return 0;
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
int A, B, C;
cin >> A >> B >> C;
int K;
cin >> K;
while ((B <= A) && (K > 0)) {
B *= 2;
K--;
}
while ((B > A) && (K > 0)) {
C *= 2;
}
if ((C > B) && (B > A)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
int A, B, C;
cin >> A >> B >> C;
int K;
cin >> K;
while ((B <= A) && (K > 0)) {
B *= 2;
K--;
}
while ((B > A) && (K > 0)) {
C *= 2;
K--;
}
if ((C > B) && (B > A)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | insert | 16 | 16 | 16 | 17 | TLE | |
p02601 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int v[3];
for (int i = 0; i < 3; ++i)
cin >> v[i];
int k;
cin >> k;
int p = 1;
while (k--) {
if (v[p] <= v[p - 1])
v[p] *= 2;
else
p++, k++;
}
if (v[0] < v[1] and v[1] < v[2])
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int v[3];
for (int i = 0; i < 3; ++i)
cin >> v[i];
int k;
cin >> k;
int p = 1;
while (k-- and p < 3) {
if (v[p] <= v[p - 1])
v[p] *= 2;
else
p++, k++;
}
if (v[0] < v[1] and v[1] < v[2])
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02601 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c, k;
cin >> a >> b >> c >> k;
for (int i = 0; i <= k; ++i) {
int B = b;
for (int j = 0; j < i; ++j) {
B *= 2;
}
for (int j = 0; i + j <= k; ++j) {
int C = c;
for (int x = 0; x < j; ++x) {
C *= 2;
}
if (a < B && B < C) {
cout << "Yes\n";
return 9;
}
}
}
cout << "No\n";
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c, k;
cin >> a >> b >> c >> k;
for (int i = 0; i <= k; ++i) {
int B = b;
for (int j = 0; j < i; ++j) {
B *= 2;
}
for (int j = 0; i + j <= k; ++j) {
int C = c;
for (int x = 0; x < j; ++x) {
C *= 2;
}
if (a < B && B < C) {
cout << "Yes\n";
return 0;
}
}
}
cout << "No\n";
} | replace | 63 | 64 | 63 | 64 | 9 | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define sws \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define fo(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
sws;
int a, b, c, k;
cin >> a >> b >> c >> k;
while (k > 0) {
while (k > 0 and (c <= a or c <= b)) {
c *= 2;
k--;
}
while (k > 0 and b <= a) {
b *= 2;
k--;
}
}
if (b > a and c > a and c > b) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define sws \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define fo(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
sws;
int a, b, c, k;
cin >> a >> b >> c >> k;
while (k > 0 and (c <= a or b <= a or c <= b)) {
while (k > 0 and (c <= a or c <= b)) {
c *= 2;
k--;
}
while (k > 0 and b <= a) {
b *= 2;
k--;
}
}
if (b > a and c > a and c > b) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
} | replace | 28 | 29 | 28 | 29 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, l, r) for (int i = (l); i < (r); i++)
int main() {
int A, B, C;
cin >> A >> B >> C;
int K;
cin >> K;
while (K) {
if (A >= B) {
B *= 2;
K--;
} else
break;
}
while (K) {
if (B >= C) {
C *= 2;
K--;
}
}
if (A < B && B < C) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, l, r) for (int i = (l); i < (r); i++)
int main() {
int A, B, C;
cin >> A >> B >> C;
int K;
cin >> K;
while (K) {
if (A >= B) {
B *= 2;
K--;
} else
break;
}
while (K) {
if (B >= C) {
C *= 2;
K--;
} else
break;
}
if (A < B && B < C) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 22 | 23 | 22 | 24 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define ll long long int
int main() {
int a, b, c;
int k;
cin >> a >> b >> c;
cin >> k;
int i = 0, x = 0;
int flag = 0;
while (i < k) {
if (x == 0) {
if (b <= a) {
b *= 2;
i++;
}
if (b > a) {
x = 1;
}
} else if (x == 1) {
if (c <= b) {
c *= 2;
i++;
}
if (c > b) {
flag = 1;
}
}
}
if (flag == 1)
cout << "Yes";
else
cout << "No";
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define ll long long int
int main() {
int a, b, c;
int k;
cin >> a >> b >> c;
cin >> k;
int i = 0, x = 0;
int flag = 0;
while (i < k) {
if (x == 0) {
if (b <= a) {
b *= 2;
i++;
}
if (b > a) {
x = 1;
}
} else if (x == 1) {
if (c <= b) {
c *= 2;
i++;
}
if (c > b) {
flag = 1;
break;
}
}
}
if (flag == 1)
cout << "Yes";
else
cout << "No";
return 0;
} | insert | 34 | 34 | 34 | 35 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <string.h>
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
using namespace std;
int nxt() {
int x;
cin >> x;
return x;
}
ll nxtl() {
ll x;
cin >> x;
return x;
}
void SieveOfEratosthenes(int n, vector<int> &primes) {
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a prime
if (prime[p] == true) {
// Update all multiples of p greater than or
// equal to the square of it
// numbers which are multiple of p and are
// less than p^2 are already been marked.
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
// Print all prime numbers
for (int p = 2; p <= n; p++)
if (prime[p])
primes.push_back(p);
}
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll power(ll x, ll y, ll mod) {
ll temp;
if (y == 0)
return 1;
temp = power(x, y / 2, mod);
if (y % 2 == 0)
return (temp * temp) % mod;
else
return (((x * temp) % mod) * temp) % mod;
}
ll modPow(ll a, ll x, ll p) {
// calculates a^x mod p in logarithmic time.
ll res = 1;
while (x > 0) {
if (x % 2 != 0) {
res = (res * a) % p;
}
a = (a * a) % p;
x /= 2;
}
return res;
}
ll modInverse(ll a, ll p) {
// calculates the modular multiplicative of a mod m.
//(assuming p is prime).
return modPow(a, p - 2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).
ll numerator = 1; // n * (n-1) * ... * (n-k+1)
for (int i = 0; i < k; i++) {
numerator = (numerator * (n - i)) % p;
}
ll denominator = 1; // k!
for (int i = 1; i <= k; i++) {
denominator = (denominator * i) % p;
}
// numerator / denominator mod p.
return (numerator * modInverse(denominator, p)) % p;
}
ll f[200001];
ll pow(ll a, ll b, ll MOD) {
ll x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x > MOD)
x %= MOD;
}
y = (y * y);
if (y > MOD)
y %= MOD;
b /= 2;
}
return x;
}
/* Modular Multiplicative Inverse
Using Euler's Theorem
a^(phi(m)) = 1 (mod m)
a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD) { return pow(n, MOD - 2, MOD); }
ll C(ll n, ll r, ll MOD) {
return (f[n] *
((InverseEuler(f[r], MOD) * InverseEuler(f[n - r], MOD)) % MOD)) %
MOD;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a = nxt(), b = nxt(), c = nxt();
int k = nxt();
while (k) {
if (b <= a) {
k--;
b *= 2;
} else if (c <= b) {
k--;
c *= 2;
}
}
if (b > a && c > b)
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| #include <bits/stdc++.h>
#include <string.h>
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
using namespace std;
int nxt() {
int x;
cin >> x;
return x;
}
ll nxtl() {
ll x;
cin >> x;
return x;
}
void SieveOfEratosthenes(int n, vector<int> &primes) {
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a prime
if (prime[p] == true) {
// Update all multiples of p greater than or
// equal to the square of it
// numbers which are multiple of p and are
// less than p^2 are already been marked.
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
// Print all prime numbers
for (int p = 2; p <= n; p++)
if (prime[p])
primes.push_back(p);
}
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll power(ll x, ll y, ll mod) {
ll temp;
if (y == 0)
return 1;
temp = power(x, y / 2, mod);
if (y % 2 == 0)
return (temp * temp) % mod;
else
return (((x * temp) % mod) * temp) % mod;
}
ll modPow(ll a, ll x, ll p) {
// calculates a^x mod p in logarithmic time.
ll res = 1;
while (x > 0) {
if (x % 2 != 0) {
res = (res * a) % p;
}
a = (a * a) % p;
x /= 2;
}
return res;
}
ll modInverse(ll a, ll p) {
// calculates the modular multiplicative of a mod m.
//(assuming p is prime).
return modPow(a, p - 2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).
ll numerator = 1; // n * (n-1) * ... * (n-k+1)
for (int i = 0; i < k; i++) {
numerator = (numerator * (n - i)) % p;
}
ll denominator = 1; // k!
for (int i = 1; i <= k; i++) {
denominator = (denominator * i) % p;
}
// numerator / denominator mod p.
return (numerator * modInverse(denominator, p)) % p;
}
ll f[200001];
ll pow(ll a, ll b, ll MOD) {
ll x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x > MOD)
x %= MOD;
}
y = (y * y);
if (y > MOD)
y %= MOD;
b /= 2;
}
return x;
}
/* Modular Multiplicative Inverse
Using Euler's Theorem
a^(phi(m)) = 1 (mod m)
a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD) { return pow(n, MOD - 2, MOD); }
ll C(ll n, ll r, ll MOD) {
return (f[n] *
((InverseEuler(f[r], MOD) * InverseEuler(f[n - r], MOD)) % MOD)) %
MOD;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a = nxt(), b = nxt(), c = nxt();
int k = nxt();
while (k) {
if (b <= a) {
k--;
b *= 2;
} else {
k--;
c *= 2;
}
}
if (b > a && c > b)
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| replace | 137 | 138 | 137 | 138 | TLE | |
p02601 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define x first
#define y second
const int MOD = 1e9 + 7;
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen((s+".in").c_str(),"r",stdin);
// freopen((s+".text").c_str(),"w",stdout);
}
// ctrl q is comment
// ctrl b is run
// ctrl s is compile
// alt r is search & replace
// alt d is delete a line
int main() {
setIO();
int a, b, c, K;
cin >> a >> b >> c >> K;
int k2 = K;
bool ok = false;
int p2[10];
int p = 0, m = 1;
p2[0] = 1;
while (p < 10) {
++p;
m *= 2;
p2[p] = m;
}
K = k2;
for (int i = 0; i < 7; ++i) {
for (int j = 0; j < 7; ++j) {
for (int k = 0; k < 7; ++k) {
if (i + j + k > K)
continue;
int ra = a * p2[i];
int rb = b * p2[j];
int rc = c * p2[k];
if (rb > ra && rc > rb) {
ok = true;
}
}
}
}
cout << (ok ? "Yes\n" : "No\n");
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define x first
#define y second
const int MOD = 1e9 + 7;
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen((s+".in").c_str(),"r",stdin);
// freopen((s+".text").c_str(),"w",stdout);
}
// ctrl q is comment
// ctrl b is run
// ctrl s is compile
// alt r is search & replace
// alt d is delete a line
int main() {
setIO();
int a, b, c, K;
cin >> a >> b >> c >> K;
int k2 = K;
bool ok = false;
int p2[10];
int p = 0, m = 1;
p2[0] = 1;
while (p < 9) {
++p;
m *= 2;
p2[p] = m;
}
K = k2;
for (int i = 0; i < 7; ++i) {
for (int j = 0; j < 7; ++j) {
for (int k = 0; k < 7; ++k) {
if (i + j + k > K)
continue;
int ra = a * p2[i];
int rb = b * p2[j];
int rc = c * p2[k];
if (rb > ra && rc > rb) {
ok = true;
}
}
}
}
cout << (ok ? "Yes\n" : "No\n");
} | replace | 37 | 38 | 37 | 38 | -6 | *** stack smashing detected ***: terminated
|
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
while (k > 0) {
if (b <= a) {
b *= 2;
k--;
continue;
}
if (c <= b) {
c *= 2;
k--;
continue;
}
}
if (a < b && b < c)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
while (k > 0) {
if (b <= a) {
b *= 2;
k--;
continue;
}
if (c <= b) {
c *= 2;
k--;
continue;
}
k--;
}
if (a < b && b < c)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | insert | 21 | 21 | 21 | 22 | TLE | |
p02601 | Python | Runtime Error | a, b, c = 7, 4, 2
k = int(input())
while a >= b and k > 0:
b *= 2
k -= 1
while b >= c and k > 0:
c *= 2
k -= 1
if a < b < c:
print("Yes")
else:
print("No")
| a, b, c = map(int, input().split())
k = int(input())
while a >= b and k > 0:
b *= 2
k -= 1
while b >= c and k > 0:
c *= 2
k -= 1
if a < b < c:
print("Yes")
else:
print("No")
| replace | 0 | 1 | 0 | 1 | ValueError: invalid literal for int() with base 10: '7 2 5' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02601/Python/s393142125.py", line 3, in <module>
k = int(input())
ValueError: invalid literal for int() with base 10: '7 2 5'
|
p02601 | Python | Time Limit Exceeded | A, B, C = map(int, input().split())
K = int(input())
while K > 0:
if A >= B:
B *= 2
K -= 1
elif B >= C:
C *= 2
K -= 1
if C > B and B > A:
print("Yes")
else:
print("No")
| A, B, C = map(int, input().split())
K = int(input())
while K > 0:
if A >= B:
B *= 2
K -= 1
elif B >= C:
C *= 2
K -= 1
if C > B and B > A:
break
if C > B and B > A:
print("Yes")
else:
print("No")
| insert | 10 | 10 | 10 | 12 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
while (k > 0) {
if (c <= b || c <= a) {
c *= 2;
k--;
}
else if (b <= a) {
b *= 2;
k--;
}
}
(c > b && b > a) ? cout << "Yes" << endl : cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
while (k > 0) {
if (c <= b || c <= a) {
c *= 2;
k--;
}
else if (b <= a) {
b *= 2;
k--;
} else if (c > b && b > a) {
break;
}
}
(c > b && b > a) ? cout << "Yes" << endl : cout << "No" << endl;
return 0;
} | insert | 18 | 18 | 18 | 20 | TLE | |
p02601 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
int A, B, C, K;
cin >> A >> B >> C >> K;
vector<int> success;
for (int r = 0; r <= K; r++) {
for (int g = 0; g <= K; g++) {
for (int b = 0; b <= K; b++) {
int rval = A * (1 << r);
int gval = B * (1 << g);
int bval = C * (1 << b);
if (rval < gval && gval < bval)
success.push_back(r + g + b);
}
}
}
int min_op = *min_element(success.begin(), success.end());
if (min_op <= K) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
int A, B, C, K;
cin >> A >> B >> C >> K;
vector<int> success;
for (int r = 0; r <= K; r++) {
for (int g = 0; g <= K; g++) {
for (int b = 0; b <= K; b++) {
int rval = A * (1 << r);
int gval = B * (1 << g);
int bval = C * (1 << b);
if (rval < gval && gval < bval)
success.push_back(r + g + b);
}
}
}
int min_op = 0;
if (success.size() > 0) {
min_op = *min_element(success.begin(), success.end());
} else {
cout << "No" << endl;
return 0;
}
if (min_op <= K) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| replace | 22 | 23 | 22 | 29 | 0 | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5, mod = 1e9 + 7;
void solve() {
int r, g, b;
cin >> r >> g >> b;
int k;
cin >> k;
while (k) {
if (g <= r) {
g *= 2;
--k;
} else if (b <= g) {
b *= 2;
--k;
}
}
if (g > r && b > g) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5, mod = 1e9 + 7;
void solve() {
int r, g, b;
cin >> r >> g >> b;
int k;
cin >> k;
while (k) {
if (g <= r) {
g *= 2;
--k;
} else if (b <= g) {
b *= 2;
--k;
}
if (g > r && b > g) {
break;
}
}
if (g > r && b > g) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
| insert | 21 | 21 | 21 | 24 | TLE | |
p02601 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
int cnt = 0;
cin >> a >> b >> c >> k;
while (a >= b) {
cnt += 1;
b *= 2;
}
while (b >= c) {
cnt += 1;
c * 2;
}
if (cnt <= k)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
int cnt = 0;
cin >> a >> b >> c >> k;
while (a >= b) {
cnt += 1;
b *= 2;
}
while (b >= c) {
cnt += 1;
c *= 2;
}
if (cnt <= k)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p02602 | C++ | Runtime Error | #include <stdio.h>
int main() {
long long int n, k;
scanf("%lld", &n);
scanf("%lld", &k);
long long int a[100];
for (long long int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
for (long long int j = 0; j < n - k; j++) {
if (a[k + j] > a[j]) {
printf("Yes\n");
} else
printf("No\n");
}
return 0;
} | #include <stdio.h>
int main() {
long long int n, k;
scanf("%lld", &n);
scanf("%lld", &k);
long long int a[200000];
for (long long int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
for (long long int j = 0; j < n - k; j++) {
if (a[k + j] > a[j]) {
printf("Yes\n");
} else
printf("No\n");
}
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02602 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
long N;
cin >> N;
long K;
cin >> K;
vector<long> avec;
vector<long> zeros;
for (long i = 0; i < N; ++i) {
long a;
cin >> a;
avec.emplace_back(a);
if (a == 0) {
zeros.emplace_back(i);
}
}
unsigned int currentZeroIdx = 0u;
int currentZero = -1;
if (zeros.size() > 0) {
currentZero = zeros[currentZeroIdx];
}
for (long i = K; i < N; ++i) {
if (currentZero < i - K + 1) {
currentZeroIdx++;
if (zeros.size() - 1 < currentZeroIdx) {
currentZero = -1;
} else {
currentZero = zeros[currentZeroIdx];
}
}
if ((currentZero != -1) && (i - K + 1 <= currentZero && currentZero < i)) {
cout << "No" << endl;
} else {
if (avec[i] > avec[i - K]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
long N;
cin >> N;
long K;
cin >> K;
vector<long> avec;
vector<long> zeros;
for (long i = 0; i < N; ++i) {
long a;
cin >> a;
avec.emplace_back(a);
if (a == 0) {
zeros.emplace_back(i);
}
}
unsigned int currentZeroIdx = 0u;
int currentZero = -1;
if (zeros.size() > 0) {
currentZero = zeros[currentZeroIdx];
}
for (long i = K; i < N; ++i) {
if ((zeros.size() > 0) && currentZero < i - K + 1) {
currentZeroIdx++;
if (zeros.size() - 1 < currentZeroIdx) {
currentZero = -1;
} else {
currentZero = zeros[currentZeroIdx];
}
}
if ((currentZero != -1) && (i - K + 1 <= currentZero && currentZero < i)) {
cout << "No" << endl;
} else {
if (avec[i] > avec[i - K]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
} | replace | 25 | 26 | 25 | 26 | -11 | |
p02602 | C++ | Runtime Error | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define mod 1000000007
vector<ll> to[1000005];
ll dp[2000000];
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
ll a, b;
cin >> a >> b;
vector<ll> c(a);
rep(i, a) cin >> c[i];
rep(i, b - 1) {
if (c[i] < c[i + b])
cout << "Yes" << endl;
else
cout << "No" << endl;
// cout<<c[i+b];
}
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define mod 1000000007
vector<ll> to[1000005];
ll dp[2000000];
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
ll a, b;
cin >> a >> b;
vector<ll> c(a);
rep(i, a) cin >> c[i];
rep(i, a - b) {
if (c[i] < c[i + b])
cout << "Yes" << endl;
else
cout << "No" << endl;
// cout<<c[i+b];
}
}
| replace | 39 | 40 | 39 | 40 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <numeric>
using namespace std;
int main() {
int n, k;
vector<int> a(n);
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = k; i < n; ++i) {
if (a[i - k] < a[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
#include <numeric>
using namespace std;
int main() {
int n, k;
int a[200005];
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = k; i < n; ++i) {
if (a[i - k] < a[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| replace | 6 | 7 | 6 | 7 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02602 | C++ | Runtime Error | /*
Author:zeke
pass System Test!
GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
ll(s); \
cin >> (s);
#define Scin(s) \
ll(s); \
cin >> (s);
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n, k;
cin >> n >> k;
queue<ll> q;
rep(i, k) {
ll x;
cin >> x;
q.push(x);
}
rep3(i, k, n) {
ll x;
cin >> x;
ll y = q.front();
q.pop();
if (x > y) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| /*
Author:zeke
pass System Test!
GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
ll(s); \
cin >> (s);
#define Scin(s) \
ll(s); \
cin >> (s);
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n, k;
cin >> n >> k;
queue<ll> q;
rep(i, k) {
ll x;
cin >> x;
q.push(x);
}
rep3(i, k, n) {
ll x;
cin >> x;
ll y = q.front();
q.pop();
q.push(x);
if (x > y) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| insert | 76 | 76 | 76 | 77 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
int n, k;
cin >> n >> k;
V<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
V<ll> sums(n + 2, 1);
for (int i = 0; i < n; i++) {
sums[i + 2] = sums[i + 1] * a[i];
}
V<ll> ans;
for (int i = k + 1; i <= n + 1; i++) {
ans.push_back(sums[i] / sums[i - k]);
}
for (int i = 1; i < (int)ans.size(); i++) {
if (ans[i - 1] < ans[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
int n, k;
cin >> n >> k;
V<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = k; i < n; i++) {
if (a[i - k] < a[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| replace | 17 | 28 | 17 | 19 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define sd(t) scanf("%d", &(t))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
#define hey cout << "hey" << endl
const int INF = 1e12;
const int MOD = 1e9 + 7;
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (T i : v)
os << i << ' ';
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
for (T i : v)
os << i << ' ';
return os;
}
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << v.x << ' ' << v.y;
return os;
}
template <class T, class S>
ostream &operator<<(ostream &os, const unordered_map<T, S> &v) {
for (auto i : v)
os << '(' << i.x << "=>" << i.y << ')' << ' ';
return os;
}
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <class Arg1, class... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *sep = strchr(names + 1, ',');
cerr.write(names, sep - names) << " : " << arg1 << " ";
__f(sep + 1, args...);
}
#else
#define trace(...)
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
"avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
clock_t time_p = clock();
void starboy1299() {
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("jjj.txt", "w", stdout);
#endif
}
void solve() {
int n, k;
cin >> n >> k;
vi arr(n);
rep(i, 0, n) { cin >> arr[i]; }
int val = 1;
for (int i = 0; i <= k - 2; i++) {
val *= arr[i];
}
// cout << val << endl;
vi ans;
int temp = 1;
for (int i = k - 1; i < n; i++) {
val = val * arr[i];
int curr = val / temp;
temp *= arr[i - k + 1];
// cout << curr << endl;
ans.pb(curr);
}
// cout << ans << endl;
for (int i = 1; i < ans.size(); i++) {
// cout << arr[i] - arr[i-1] << endl;
if ((ans[i] - ans[i - 1]) > 0) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
}
int32_t main() {
fast();
int t = 1;
// cin>> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
solve();
}
starboy1299();
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define sd(t) scanf("%d", &(t))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
#define hey cout << "hey" << endl
const int INF = 1e12;
const int MOD = 1e9 + 7;
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (T i : v)
os << i << ' ';
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
for (T i : v)
os << i << ' ';
return os;
}
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << v.x << ' ' << v.y;
return os;
}
template <class T, class S>
ostream &operator<<(ostream &os, const unordered_map<T, S> &v) {
for (auto i : v)
os << '(' << i.x << "=>" << i.y << ')' << ' ';
return os;
}
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <class Arg1, class... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *sep = strchr(names + 1, ',');
cerr.write(names, sep - names) << " : " << arg1 << " ";
__f(sep + 1, args...);
}
#else
#define trace(...)
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
"avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
clock_t time_p = clock();
void starboy1299() {
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("jjj.txt", "w", stdout);
#endif
}
void solve() {
int n, k;
cin >> n >> k;
vi arr(n);
rep(i, 0, n) { cin >> arr[i]; }
for (int i = k; i < n; i++) {
if (arr[i] > arr[i - k]) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
}
int32_t main() {
fast();
int t = 1;
// cin>> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
solve();
}
starboy1299();
} | replace | 95 | 115 | 95 | 97 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02602 | C++ | Runtime Error | /**
** author : Raghav
** codechef:raghav_456
** codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl "\n"
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define deb(x) cout << #x << " " << x << endl
#define ar array
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void Raghav() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
bool compare(pair<int, int> &a, pair<int, int> &b) { return a.first < b.first; }
int cb(int number) { return (int)log2(number) + 1; }
int32_t main() {
Raghav();
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i < k; i++) {
if (v[i] < v[i + k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | /**
** author : Raghav
** codechef:raghav_456
** codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl "\n"
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define deb(x) cout << #x << " " << x << endl
#define ar array
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void Raghav() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
bool compare(pair<int, int> &a, pair<int, int> &b) { return a.first < b.first; }
int cb(int number) { return (int)log2(number) + 1; }
int32_t main() {
Raghav();
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n - k; i++) {
if (v[i] < v[i + k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 59 | 60 | 59 | 60 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02602 | C++ | Runtime Error | #include <stdio.h>
int main() {
int n, k;
scanf("%d %d", &n, &k);
int lt[n];
for (int i = 0; i < n; i++) {
scanf("%d", <[i]);
}
int c = n - k;
for (int i = 0; i < c; i++) {
if (lt[i] < lt[i + c]) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
} | #include <stdio.h>
int main() {
int n, k;
scanf("%d %d", &n, &k);
int lt[n];
for (int i = 0; i < n; i++) {
scanf("%d", <[i]);
}
int c = n - k;
for (int i = 0; i < c; i++) {
if (lt[i] < lt[i + k]) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> s(n + 1);
s[0] = 1;
rep(i, n) s[i + 1] = s[i] * a[i];
for (int i = k + 1; i <= n; i++) {
if (s[i] / s[i - k] > s[i - 1] / s[i - k - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
for (int i = k; i < n; i++) {
if (a[i - k] < a[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 10 | 15 | 10 | 12 | 0 | |
p02602 | C++ | Runtime Error | #define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using numr = std::numeric_limits<T>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
std::cerr << " " << head;
debug_impl(tail...);
}
#if DEBUG
#define debug(...) \
do { \
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:"; \
debug_impl(__VA_ARGS__); \
std::cerr << std::noboolalpha; \
} while (false)
#else
#define debug(...) \
{}
#endif
template <typename Container, typename Value = typename Container::value_type,
std::enable_if_t<!std::is_same<Container, std::string>::value,
std::nullptr_t> = nullptr>
std::istream &operator>>(std::istream &is, Container &v) {
for (auto &x : v) {
is >> x;
}
return is;
}
template <typename Container, typename Value = typename Container::value_type,
std::enable_if_t<!std::is_same<Container, std::string>::value,
std::nullptr_t> = nullptr>
std::ostream &operator<<(std::ostream &os, Container const &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); it++) {
os << (it != v.begin() ? "," : "") << *it;
}
return os << "}";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<ll> a(n);
cin >> a;
vector<ll> v(n + 1, 1);
for (int i = 0; i < n; i++) {
v[i + 1] = v[i] * a[i];
}
vector<ll> c;
for (int i = 0; i + k <= n; i++) {
ll now = v[i + k] / v[i];
c.emplace_back(now);
}
// cout << c <<endl;
for (int i = 1; i < c.size(); i++) {
if (c[i - 1] < c[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
} | #define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using numr = std::numeric_limits<T>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
std::cerr << " " << head;
debug_impl(tail...);
}
#if DEBUG
#define debug(...) \
do { \
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:"; \
debug_impl(__VA_ARGS__); \
std::cerr << std::noboolalpha; \
} while (false)
#else
#define debug(...) \
{}
#endif
template <typename Container, typename Value = typename Container::value_type,
std::enable_if_t<!std::is_same<Container, std::string>::value,
std::nullptr_t> = nullptr>
std::istream &operator>>(std::istream &is, Container &v) {
for (auto &x : v) {
is >> x;
}
return is;
}
template <typename Container, typename Value = typename Container::value_type,
std::enable_if_t<!std::is_same<Container, std::string>::value,
std::nullptr_t> = nullptr>
std::ostream &operator<<(std::ostream &os, Container const &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); it++) {
os << (it != v.begin() ? "," : "") << *it;
}
return os << "}";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<ll> a(n);
cin >> a;
for (int i = 0; i + k < n; i++) {
if (a[i] < a[i + k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
} | replace | 76 | 88 | 76 | 78 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int a[20000];
int main() {
int N, K, i;
scanf("%d%d", &N, &K);
for (i = 0; i < N; i++)
scanf("%d", &a[i]);
for (i = 0; i < N - K; i++)
if (a[i] < a[K + i])
printf("Yes\n");
else
printf("No\n");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int a[200001];
int main() {
int N, K, i;
scanf("%d%d", &N, &K);
for (i = 0; i < N; i++)
scanf("%d", &a[i]);
for (i = 0; i < N - K; i++)
if (a[i] < a[K + i])
printf("Yes\n");
else
printf("No\n");
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
using P = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll MOD = 1000000007;
ll INF = 1 << 30;
int main() {
int n, k;
cin >> n >> k;
vector<int> A(n);
rep(i, n) cin >> A[i];
rep(i, k + i < n) {
if (A[k + i] > A[i]) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
using P = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll MOD = 1000000007;
ll INF = 1 << 30;
int main() {
int n, k;
cin >> n >> k;
vector<int> A(n);
rep(i, n) cin >> A[i];
rep(i, n - k) {
if (A[k + i] > A[i]) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
} | replace | 31 | 32 | 31 | 32 | -11 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
void solve(long long N, long long K, std::vector<long long> A) {
vector<long long> cumsum(N, 0);
cumsum[0] = A[0];
for (long long i = 1; i <= N; ++i) {
cumsum[i] = cumsum[i - 1] * A[i];
}
// for(long long i = 0; i < N; ++i) cout << cumsum[i] << endl;
// cout << cumsum[K-1] << endl;
// for(long long i = K; i < N; ++i) cout << cumsum[i] / cumsum[i-K] << endl;
for (long long i = K; i < N; ++i) {
if (i == K) {
if (cumsum[i] / cumsum[i - K] > cumsum[i - 1])
cout << YES << endl;
else
cout << NO << endl;
} else {
if ((cumsum[i] / cumsum[i - K]) > (cumsum[i - 1] / cumsum[i - K - 1]))
cout << YES << endl;
else
cout << NO << endl;
}
}
}
int main() {
long long N;
scanf("%lld", &N);
long long K;
scanf("%lld", &K);
std::vector<long long> A(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &A[i]);
}
solve(N, K, std::move(A));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
void solve(long long N, long long K, std::vector<long long> A) {
for (int i = K; i < N; ++i) {
// cout << A[i] << ":" << A[i-K] << endl;
if (A[i] > A[i - K])
cout << YES << endl;
else
cout << NO << endl;
}
}
int main() {
long long N;
scanf("%lld", &N);
long long K;
scanf("%lld", &K);
std::vector<long long> A(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &A[i]);
}
solve(N, K, std::move(A));
return 0;
}
| replace | 7 | 27 | 7 | 13 | -6 | malloc(): corrupted top size
|
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
vector<int64_t> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
int64_t chk = N - K;
for (int i = 0; i < chk; i++) {
if (A.at(i) < A.at(i + chk - 1)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
vector<int64_t> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
for (int i = 0; i < N - K; i++) {
if (A.at(i) < A.at(i + K)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
} | replace | 10 | 13 | 10 | 12 | 0 | |
p02602 | Python | Time Limit Exceeded | n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
score: list = []
for i in range(k - 1, n):
tmp_score = 1
for j in range(k):
tmp_score *= a[i - j]
score.append(tmp_score)
for i in range(len(score) - 1):
# print(score[i], score[i + 1])
if score[i + 1] > score[i]:
print("Yes")
else:
print("No")
| n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
for i in range(k, n):
if a[i - k] < a[i]:
print("Yes")
else:
print("No")
| replace | 3 | 13 | 3 | 5 | TLE | |
p02602 | Python | Runtime Error | from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
if i < k - 1:
queue.append(a[i])
elif i >= k:
x = queue.popleft()
if x < a[i]:
print("Yes")
else:
print("No")
queue.append(a[i])
| from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
if i <= k - 1:
queue.append(a[i])
elif i >= k:
x = queue.popleft()
if x < a[i]:
print("Yes")
else:
print("No")
queue.append(a[i])
| replace | 6 | 7 | 6 | 7 | 0 | |
p02602 | Python | Time Limit Exceeded | n, k = map(int, input().split())
aa = tuple(map(int, input().split()))
s = 1
ps = 1
for i in range(n):
s *= aa[i]
if i >= k:
s //= aa[i - k]
if ps < s:
print("Yes")
else:
print("No")
ps = s
| n, k = map(int, input().split())
aa = tuple(map(int, input().split()))
for i in range(k, n):
if aa[i - k] < aa[i]:
print("Yes")
else:
print("No")
| replace | 3 | 14 | 3 | 8 | TLE | |
p02602 | Python | Time Limit Exceeded | s = input().split()
N = int(s[0])
K = int(s[1])
A = input().split()
for i in range(K, N):
m1 = 1
m2 = 1
for j in range(K):
m1 *= int(A[i - j - 1])
m2 *= int(A[i - j - 0])
print("Yes" if m1 < m2 else "No")
| s = input().split()
N = int(s[0])
K = int(s[1])
A = input().split()
for i in range(K, N):
m1 = int(A[i - K])
m2 = int(A[i])
print("Yes" if m1 < m2 else "No")
| replace | 6 | 11 | 6 | 8 | TLE | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ford(i, a, b) for (int i = (a); i >= b; i--)
#define rep1(i, a, b) for (int i = (a); (i) <= (b); (i)++)
#define rep(i, a, b) for (int i = (a); (i) < (b); (i)++)
#define ll long long
#define N 105
#define pql priority_queue<ll>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rev(a, n) reverse(a, a + n)
using namespace std;
int n, k, a[N];
int main() {
cin >> n >> k;
rep1(i, 1, n) {
cin >> a[i];
if (i > k) {
if (a[i - k] < a[i])
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
| #include <bits/stdc++.h>
#define ford(i, a, b) for (int i = (a); i >= b; i--)
#define rep1(i, a, b) for (int i = (a); (i) <= (b); (i)++)
#define rep(i, a, b) for (int i = (a); (i) < (b); (i)++)
#define ll long long
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rev(a, n) reverse(a, a + n)
using namespace std;
int n, k, a[N];
int main() {
cin >> n >> k;
rep1(i, 1, n) {
cin >> a[i];
if (i > k) {
if (a[i - k] < a[i])
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9, mod = 1e9 + 7;
#define endl '\n'
int a[20005];
void solve() {}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n - k; i++) {
cout << (a[i] < a[i + k] ? "Yes\n" : "No\n");
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9, mod = 1e9 + 7;
#define endl '\n'
int a[200005];
void solve() {}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n - k; i++) {
cout << (a[i] < a[i + k] ? "Yes\n" : "No\n");
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(vs) (ll)(vs.size())
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rep_(i, a, b) for (ll i = a; i > b; --i)
#define iter(i, c) for (auto i : c)
#define endl '\n'
const ll mod = 1e9 + 7;
const ll maxn = 1e5;
ll n, k;
ll a[maxn];
void solve() {
cin >> n >> k;
rep(i, 0, n) cin >> a[i];
rep(i, k, n) {
if (a[i] > a[i - k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
void aux() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
aux();
ll _ = 1;
// cin>>_;
while (_--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(vs) (ll)(vs.size())
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rep_(i, a, b) for (ll i = a; i > b; --i)
#define iter(i, c) for (auto i : c)
#define endl '\n'
const ll mod = 1e9 + 7;
const ll maxn = 2e6 + 5;
ll n, k;
ll a[maxn];
void solve() {
cin >> n >> k;
rep(i, 0, n) cin >> a[i];
rep(i, k, n) {
if (a[i] > a[i - k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
void aux() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
aux();
ll _ = 1;
// cin>>_;
while (_--) {
solve();
}
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> s(n + 1);
s[0] = 1;
for (ll i = 0; i < n; ++i) {
s[i + 1] = s[i] * a[i];
}
for (ll i = k; i < n; ++i) {
ll x = s[i] / s[i - k];
ll y = s[i + 1] / s[i + 1 - k];
if (x < y) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll i = 0; i < n; ++i) {
cin >> a[i];
}
for (ll i = 0; i < n - k; ++i) {
if (a[i] < a[i + k]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| replace | 11 | 20 | 11 | 13 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define PER(i, n) for (ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll &a, const ll &b) { return ((a) + (b)-1) / b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n, k;
cin >> n >> k;
vi a(n);
rep(i, n) cin >> a[i];
for (int i = k; i < n; i++) {
YesorNo(a[k - i] < a[i]);
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define PER(i, n) for (ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll &a, const ll &b) { return ((a) + (b)-1) / b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n, k;
cin >> n >> k;
vi a(n);
rep(i, n) cin >> a[i];
for (int i = k; i < n; i++) {
YesorNo(a[i - k] < a[i]);
}
} | replace | 54 | 55 | 54 | 55 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<ll> t(n + 1, 1);
vector<ll> ans(n - k);
int count = 0;
for (int i = 1; i < n + 1; i++) {
t[i] = t[i - 1] * a[i - 1];
if (i == k) {
ans[count] = t[i];
count++;
}
if (i > k) {
ans[count] = t[i] / t[i - k];
cout << ans[count] << endl;
count++;
}
}
for (int i = 0; i < n - k; i++) {
if (ans[i] < ans[i + 1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = k; i < n; i++) {
if (a[i - k] < a[i]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| replace | 15 | 34 | 15 | 17 | 0 | |
p02602 | C++ | Runtime Error | #include <stdio.h>
int n, k;
int a[100010];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
for (int i = k + 1; i <= n; i++) {
if (a[i] > a[i - k])
puts("Yes");
else
puts("No");
}
return 0;
} | #include <stdio.h>
int n, k;
int a[200010];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
for (int i = k + 1; i <= n; i++) {
if (a[i] > a[i - k])
puts("Yes");
else
puts("No");
}
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
int main() {
using namespace std;
long long n, k, a[2000];
cin >> n >> k;
for (long long j = 0; j < n; ++j) {
cin >> a[j];
}
for (long long i = 0; i < n - k; ++i) {
if (a[i] < a[i + k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
int main() {
using namespace std;
long long n, k, a[200000];
cin >> n >> k;
for (long long j = 0; j < n; ++j) {
cin >> a[j];
}
for (long long i = 0; i < n - k; ++i) {
if (a[i] < a[i + k])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02602 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 1111LL
#define cout1(x) cout << x << "\n";
#define deb(x) cout << #x << " " << x << "\n";
#define vii vector<pa>;
using namespace std;
#define MAXN 1000000ll
// template<typename... T>
// void read(T&... args){
// ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
// ((cout<<args<<"\n"), ...);
// }
v visited(N);
vector<ll> ans = {-1};
v level(N);
v ind(N);
ll sz[N];
// void dfs(ll node, ll par){
// visited[node]=1;
// if (node==1)level[1]=0;
// else level[node] = level[par]+1;
// ans.pb(node);
// for(auto x:graph[node]){
// if (!visited[x]){
// dfs(x,node);
// sz[node]+=sz[x];
// }
// }
// ++sz[node];
// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
// cout<<ans<<" "<<x<<endl;
// if (cnt[ans%x]==0)return ans;
// else if (cnt[ans%x==1] && ans>x)return ans;
// else{
// cnt[ans%x]-=1;
// cnt[ans]+=1;
// answer(ans+1,x);
// }
// }
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
ll power(ll x, unsigned ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
auto primeFactors(ll n) {
map<ll, ll> fact;
// Print the number of 2s that divide n
while (n % 2 == 0) {
fact[2] += 1;
n = n / 2;
}
for (ll i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
fact[i] += 1;
n = n / i;
}
}
if (n > 2)
fact[n] += 1;
return fact;
}
auto getFactorization(int x) {
map<ll, ll> ret;
;
while (x != 1) {
ret[spf[x]] += 1;
x = x / spf[x];
}
return ret;
}
ll solve() {
ll n, k;
cin >> n >> k;
v arr(n);
f(i, n) cin >> arr[i];
loop(i, k, n) {
if (arr[i] > arr[i - k])
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
}
int main() {
fastio;
ll tests = 1;
// cin>>tests;
while (tests--)
solve();
}
| #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 1111LL
#define cout1(x) cout << x << "\n";
#define deb(x) cout << #x << " " << x << "\n";
#define vii vector<pa>;
using namespace std;
#define MAXN 1000000ll
// template<typename... T>
// void read(T&... args){
// ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
// ((cout<<args<<"\n"), ...);
// }
v visited(N);
vector<ll> ans = {-1};
v level(N);
v ind(N);
ll sz[N];
// void dfs(ll node, ll par){
// visited[node]=1;
// if (node==1)level[1]=0;
// else level[node] = level[par]+1;
// ans.pb(node);
// for(auto x:graph[node]){
// if (!visited[x]){
// dfs(x,node);
// sz[node]+=sz[x];
// }
// }
// ++sz[node];
// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
// cout<<ans<<" "<<x<<endl;
// if (cnt[ans%x]==0)return ans;
// else if (cnt[ans%x==1] && ans>x)return ans;
// else{
// cnt[ans%x]-=1;
// cnt[ans]+=1;
// answer(ans+1,x);
// }
// }
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
ll power(ll x, unsigned ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
auto primeFactors(ll n) {
map<ll, ll> fact;
// Print the number of 2s that divide n
while (n % 2 == 0) {
fact[2] += 1;
n = n / 2;
}
for (ll i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
fact[i] += 1;
n = n / i;
}
}
if (n > 2)
fact[n] += 1;
return fact;
}
auto getFactorization(int x) {
map<ll, ll> ret;
;
while (x != 1) {
ret[spf[x]] += 1;
x = x / spf[x];
}
return ret;
}
void solve() {
ll n, k;
cin >> n >> k;
v arr(n);
f(i, n) cin >> arr[i];
loop(i, k, n) {
if (arr[i] > arr[i - k])
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
}
int main() {
fastio;
ll tests = 1;
// cin>>tests;
while (tests--)
solve();
}
| replace | 150 | 151 | 150 | 151 | 0 | |
p02602 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld", &a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for (ll i = 1; i <= stop; i++)
#define for0(i, stop) for (ll i = 0; i < stop; i++)
#define rep1(i, start) for (ll i = start; i >= 1; i--)
#define rep0(i, start) for (ll i = (start - 1); i >= 0; i--)
#define loop(i, start, stop, inc) for (ll i = start; i <= stop; i += inc)
#define pb(v, a) v.push_back(a)
#define pll pair<ll, ll>
#define mp make_pair
#define pbp(v, a, i) v.push_back(make_pair(a, i))
#define srt(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'
#define _fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;
ll bigmod(ll n,ll pow)
{
if(pow==0)
return 1;
if(pow==1)
return n%MOD;
ll ans=bigmod(n,pow/2);
ans=(ans*ans)%MOD;
if(pow%2==1)
{
ans=(ans*n)%MOD;
}
return ans%MOD;
}
ll fact[1000005];
ll nCr(ll n,ll r)
{
ll ans=fact[n];
ans=(ans*bigmod(fact[r],MOD-2))%MOD;
ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
return ans;
} */
int main() {
_fastio ll n, k, mx;
cin >> n >> k;
ll ar[200005];
for1(i, n) cin >> ar[i];
bool fl = true;
for (ll i = 1; i <= (n - k + 1); i++) {
ll sm = 0;
for (ll j = i; j < i + k; j++)
sm += ar[j];
if (i == 1)
mx = sm;
else {
if (sm > mx) {
mx = sm;
cout << "Yes" << en;
} else {
mx = sm;
cout << "No" << en;
}
}
}
}
| #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld", &a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for (ll i = 1; i <= stop; i++)
#define for0(i, stop) for (ll i = 0; i < stop; i++)
#define rep1(i, start) for (ll i = start; i >= 1; i--)
#define rep0(i, start) for (ll i = (start - 1); i >= 0; i--)
#define loop(i, start, stop, inc) for (ll i = start; i <= stop; i += inc)
#define pb(v, a) v.push_back(a)
#define pll pair<ll, ll>
#define mp make_pair
#define pbp(v, a, i) v.push_back(make_pair(a, i))
#define srt(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'
#define _fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;
ll bigmod(ll n,ll pow)
{
if(pow==0)
return 1;
if(pow==1)
return n%MOD;
ll ans=bigmod(n,pow/2);
ans=(ans*ans)%MOD;
if(pow%2==1)
{
ans=(ans*n)%MOD;
}
return ans%MOD;
}
ll fact[1000005];
ll nCr(ll n,ll r)
{
ll ans=fact[n];
ans=(ans*bigmod(fact[r],MOD-2))%MOD;
ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
return ans;
} */
int main() {
_fastio ll n, k, mx;
cin >> n >> k;
ll ar[200005];
for1(i, n) cin >> ar[i];
/*ll sm=1;
for(ll i=1;i<=k;i++)
{
sm*=ar[i];
}
mx=sm;*/
for (ll i = 2; i <= (n - k + 1); i++) {
/*sm=mx;
sm/=ar[i-1];
sm*=ar[i+k-1];
//cout<<sm<<en;*/
if (ar[i - 1] < ar[i + k - 1]) {
// mx=sm;
cout << "Yes" << en;
} else {
// mx=sm;
cout << "No" << en;
}
}
}
| replace | 67 | 82 | 67 | 84 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.