답안 #955654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955654 2024-03-31T09:11:11 Z n3rm1n Growing Trees (BOI11_grow) C++17
0 / 100
1000 ms 3020 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+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

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)
      |                          ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1054 ms 3020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 1800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1004 ms 2544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1032 ms 2704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1055 ms 2192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1059 ms 2140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 364 ms 2420 KB Output isn't correct
2 Halted 0 ms 0 KB -