This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
int a[MAXN];
vector < int > g;
void read_array()
{
cin >> n >> m;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
g.push_back(a[i]);
}
sort(g.begin(), g.end());
}
void upd(int c, int h)
{
vector < int > v;
int i = 0;
while (i < g.size())
{
if(g[i] >= h)break;
v.push_back(g[i]);
i ++;
}
//cout << i << endl;
int not_moved = i + c;
int cut_to = i + c;
while(not_moved < g.size() && g[not_moved] < g[i+c-1] + 1)
{
v.push_back(g[not_moved]);
not_moved ++;
cut_to = not_moved;
}
for (int j = i; j < min((int)(g.size()), i + c); ++ j)
v.push_back(g[j] + 1);
for (int j = cut_to; j < g.size(); ++ j)
v.push_back(g[j]);
g = v;
}
void solve()
{
char type;
int x, y;
while(m --)
{
cin >> type >> x >> y;
if(type == 'F')
{
upd(x, y);
}
else
{
/*cout << "jfieh" << endl;
for (int i = 0; i < g.size(); ++ i)
cout << g[i] << " ";
cout << endl;*/
int cut = std::distance(g.begin(), lower_bound(g.begin(), g.end(), x)) ;
int add = std::distance(g.begin(), upper_bound(g.begin(), g.end(), y));
cout << add - cut << endl;
}
}
}
int main()
{
speed();
read_array();
solve();
return 0;
}
Compilation message (stderr)
grow.cpp: In function 'void upd(int, int)':
grow.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | while (i < g.size())
| ~~^~~~~~~~~~
grow.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while(not_moved < g.size() && g[not_moved] < g[i+c-1] + 1)
| ~~~~~~~~~~^~~~~~~~~~
grow.cpp:49:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int j = cut_to; j < g.size(); ++ j)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |