#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
namespace debug {
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef ljuba
#define dbg(x...) cerr << "\e[91m" << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
}
using namespace debug;
const char nl = '\n';
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
/*
погледај сампле тестове, пре него што имплементираш (можда имаш погрешну идеју)
уместо да разматраш неке глупе случајеве на папиру, размишљај заправо о задатку
*/
const int mxN = 1e5 + 12;
struct node {
int sum, lz;
}st[4*mxN];
int n;
void build(const vi &v, int i = 1, int l2 = 0, int r2 = n-1) {
st[i].lz = 0;
if(l2 == r2) {
st[i].sum = v[l2];
return;
}
int m2 = (l2 + r2) / 2;
build(v, 2*i, l2, m2);
build(v, 2*i+1, m2+1, r2);
}
inline void assign(int i, int x) {
st[i].lz += x;
st[i].sum += x;
}
inline void push(int i) {
assign(2*i, st[i].lz);
assign(2*i+1, st[i].lz);
st[i].lz = 0;
}
int query(int l1, int i = 1, int l2 = 0, int r2 = n-1) {
if(l2 == r2) {
return st[i].sum;
}
push(i);
int m2 = (l2 + r2) / 2;
if(l1 <= m2) return query(l1, 2*i, l2, m2);
else return query(l1, 2*i+1, m2+1, r2);
}
void update(int l1, int r1, int x, int i = 1, int l2 = 0, int r2 = n-1) {
if(l1 <= l2 && r2 <= r1) {
assign(i, 1);
return;
}
push(i);
int m2 = (l2 + r2) / 2;
if(l1 <= m2) update(l1, r1, x, 2*i, l2, m2);
if(m2 < r1) update(l1, r1, x, 2*i+1, m2+1, r2);
}
void update2(int l1, int x, int i = 1, int l2 = 0, int r2 = n-1) {
if(l2 == r2) {
st[i].sum = x;
return;
}
push(i);
int m2 = (l2 + r2) / 2;
if(l1 <= m2) update2(l1, x, 2*i, l2, m2);
else update2(l1, x, 2*i+1, m2+1, r2);
}
void ispisi(int i = 1, int l2 = 0, int r2 = n-1) {
if(l2 == r2) {
cerr << st[i].sum << " ";
return;
}
push(i);
int m2 = (l2 + r2) / 2;
ispisi(2*i, l2, m2);
ispisi(2*i+1, m2+1, r2);
}
void solve() {
int m;
cin >> n >> m;
vi v(n);
for(auto &z : v)
cin >> z;
sort(all(v));
build(v);
while(m--) {
char c;
cin >> c;
if(c == 'F') {
int x, y;
cin >> x >> y;
int l = 0, r = n-1;
int gde = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(query(mid) >= y) {
gde = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
if(gde == -1)
continue;
int dokle = min(gde+x-1, n-1);
update(gde, dokle, 1);
if(dokle != n-1) {
int sledeci = dokle+1;
if(query(dokle) > query(sledeci)) {
int mesto = -1;
l = gde, r = dokle;
int vrednost = query(dokle);
while(l <= r) {
int mid = (l + r) / 2;
if(query(mid) >= vrednost) {
mesto = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
update2(mesto, vrednost-1);
update2(sledeci, vrednost);
}
}
} else {
int x, y;
cin >> x >> y;
int l = 0, r = n-1;
int levo = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(query(mid) >= x) {
levo = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
l = 0, r = n-1;
int desno = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(query(mid) <= y) {
desno = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
if(min(levo, desno) == -1 || levo > desno) {
cout << 0 << nl;
} else {
cout << desno-levo+1 << nl;
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testCases = 1;
//cin >> testCases;
while(testCases--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
218 ms |
3996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
144 ms |
1516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
149 ms |
1848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
2624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
212 ms |
3696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
185 ms |
3652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
297 ms |
4628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
252 ms |
3992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
372 ms |
5160 KB |
Output isn't correct |