Submission #955652

#TimeUsernameProblemLanguageResultExecution timeMemory
955652n3rm1nGrowing Trees (BOI11_grow)C++17
0 / 100
1046 ms3540 KiB
#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]); // cout << i << " " << g[i] << endl; i ++; } //cout << i << endl; int not_moved = i + c; int cut_to = i + c; while(not_moved < g.size() && g[not_moved] <= g[i]+1) { v.push_back(g[not_moved]); //cout << not_moved << endl; not_moved ++; cut_to = not_moved; } //cout << "smaller or eq " << v.size() << endl; for (int j = i; j < min((int)(g.size()), i + c); ++ j) v.push_back(g[j] + 1); // cout << "cut to " << cut_to << endl; 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:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     while(not_moved < g.size() && g[not_moved] <= g[i]+1)
      |           ~~~~~~~~~~^~~~~~~~~~
grow.cpp:50:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int j = cut_to; j < g.size(); ++ j)
      |                          ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...