답안 #153704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153704 2019-09-15T09:07:37 Z AlexLuchianov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 113100 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

using namespace std;

#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 1000000;
int v[1 + nmax];

vector<pair<int,int>> querys[1 + nmax];
vector<pair<int,int>> interval[1 + nmax];

int sol[1 + nmax];
int key[1 + nmax];

int aint[1 + nmax * 4];

void update(int node, int from, int to, int x, int val){
  if(from < to){
    int mid = (from + to) / 2;
    if(x <= mid)
      update(node * 2 , from, mid, x, val);
    else
      update(node * 2 + 1, mid + 1 , to, x, val);
    aint[node] = MAX(aint[node * 2], aint[node * 2 + 1]);
  } else
    aint[node] = MAX(aint[node], val);
}

int query(int node,int from, int to, int x, int y){
  if(from == x && to == y)
    return aint[node];
  else{
    int mid = (from + to) / 2;
    int result1 = 0, result2 = 0;
    if(x <= mid)
      result1 = query(node * 2, from, mid, x, MIN(y, mid));
    if(mid + 1 <= y)
      result2 = query(node * 2 + 1, mid + 1, to, MAX(mid + 1, x), y);
    return MAX(result1, result2);
  }
}

int main()
{
  int n, m;
  cin >> n >> m;
  stack<int> st;
  for(int i = 1; i <= n; i++) {
    cin >> v[i];
    while(0 < st.size() && v[st.top()] < v[i])
      st.pop();
    if(0 < st.size())
      interval[i].push_back({st.top(), v[st.top()] + v[i]});
    st.push(i);
  }
  for(int i = 1;i <= m; i++){
    int x, y;
    cin >> x >> y >> key[i];
    querys[y].push_back({x, i});
  }

  for(int i = 1;i <= n; i++){
    for(int h = 0; h < interval[i].size(); h++)
      update(1, 1, n, interval[i][h].first, interval[i][h].second);
    for(int h = 0; h < querys[i].size(); h++)
      sol[querys[i][h].second] = query(1, 1, n, querys[i][h].first , i);

  }

  for(int i = 1;i <= m; i++)
    cout << (sol[i] <= key[i]) << '\n';
  return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int h = 0; h < interval[i].size(); h++)
                    ~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:71:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int h = 0; h < querys[i].size(); h++)
                    ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 47352 KB Output is correct
2 Correct 47 ms 47480 KB Output is correct
3 Correct 47 ms 47336 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 55 ms 47352 KB Output is correct
6 Correct 57 ms 47352 KB Output is correct
7 Correct 56 ms 47352 KB Output is correct
8 Correct 48 ms 47316 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 47 ms 47480 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 47352 KB Output is correct
2 Correct 47 ms 47480 KB Output is correct
3 Correct 47 ms 47336 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 55 ms 47352 KB Output is correct
6 Correct 57 ms 47352 KB Output is correct
7 Correct 56 ms 47352 KB Output is correct
8 Correct 48 ms 47316 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 47 ms 47480 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3024 ms 113100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 326 ms 54716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 47352 KB Output is correct
2 Correct 47 ms 47480 KB Output is correct
3 Correct 47 ms 47336 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 55 ms 47352 KB Output is correct
6 Correct 57 ms 47352 KB Output is correct
7 Correct 56 ms 47352 KB Output is correct
8 Correct 48 ms 47316 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 47 ms 47480 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 47352 KB Output is correct
2 Correct 47 ms 47480 KB Output is correct
3 Correct 47 ms 47336 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 55 ms 47352 KB Output is correct
6 Correct 57 ms 47352 KB Output is correct
7 Correct 56 ms 47352 KB Output is correct
8 Correct 48 ms 47316 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 47 ms 47480 KB Output isn't correct