Submission #955653

# Submission time Handle Problem Language Result Execution time Memory
955653 2024-03-31T09:07:10 Z n3rm1n Growing Trees (BOI11_grow) C++17
0 / 100
1000 ms 2924 KB
#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]+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

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 time Memory Grader output
1 Execution timed out 1043 ms 2252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1029 ms 1872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 2588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1034 ms 2580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1018 ms 2256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 2132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 379 ms 2924 KB Output isn't correct
2 Halted 0 ms 0 KB -