Submission #153703

# Submission time Handle Problem Language Result Execution time Memory
153703 2019-09-15T09:06:14 Z AlexLuchianov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 144612 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] = 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++)
                    ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47336 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 47 ms 47388 KB Output is correct
4 Correct 47 ms 47352 KB Output is correct
5 Correct 46 ms 47308 KB Output is correct
6 Correct 49 ms 47324 KB Output is correct
7 Correct 48 ms 47404 KB Output is correct
8 Correct 48 ms 47352 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 49 ms 47304 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47336 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 47 ms 47388 KB Output is correct
4 Correct 47 ms 47352 KB Output is correct
5 Correct 46 ms 47308 KB Output is correct
6 Correct 49 ms 47324 KB Output is correct
7 Correct 48 ms 47404 KB Output is correct
8 Correct 48 ms 47352 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 49 ms 47304 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3071 ms 144612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 320 ms 56748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47336 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 47 ms 47388 KB Output is correct
4 Correct 47 ms 47352 KB Output is correct
5 Correct 46 ms 47308 KB Output is correct
6 Correct 49 ms 47324 KB Output is correct
7 Correct 48 ms 47404 KB Output is correct
8 Correct 48 ms 47352 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 49 ms 47304 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47336 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 47 ms 47388 KB Output is correct
4 Correct 47 ms 47352 KB Output is correct
5 Correct 46 ms 47308 KB Output is correct
6 Correct 49 ms 47324 KB Output is correct
7 Correct 48 ms 47404 KB Output is correct
8 Correct 48 ms 47352 KB Output is correct
9 Correct 47 ms 47352 KB Output is correct
10 Incorrect 49 ms 47304 KB Output isn't correct