답안 #497628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497628 2021-12-23T12:08:01 Z vinnipuh01 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1293 ms 38004 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
 
using namespace std;
 
const long long oo = 1000000000000000000;
 
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
 
 
/*
    ViHHiPuh
 
   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))
 
 
    cout << fixed << setprecision(6) << x;
 
 
    freopen ( "sum.in", "r", stdin )
*/

stack <int> st;
int lg = 20;
int t[ 4000001 ], mp[ 1000001 ];

vector <pair<int, int> > v;

void upd( int v, int tl, int tr, int pos, int x ) {
	if ( tl > pos || tr < pos )
		return;
	if ( tl == tr ) {
		t[ v ] = max( x, t[ v ] );
		return;
	}
	int mid = ( tl + tr ) / 2;
	upd( v + v, tl, mid, pos, x );
	upd( v + v + 1, mid + 1, tr, pos, x );
	t[ v ] = max( t[ v + v ], t[ v + v + 1 ] );
}

void gett( int v, int tl, int tr ,int l, int r ) {
	if ( tl > r || tr < l )
		return;
	if ( tl >= l && tr <= r ) {
		num = max( num, t[ v ] + 0ll );
		return;
	}
	int mid = ( tl + tr ) / 2;
	gett( v + v, tl, mid, l, r );
	gett( v + v + 1, mid + 1, tr, l, r );
}

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a[ n + 1 ];
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ];
	}
	int l[ m + 1 ], r[ m + 1 ], x[ m + 1 ];
	for ( int i = 1; i <= m;  i++ ) {
		cin >> l[ i ] >> r[ i ] >> x[ i ];
		v.push_back( { r[ i ], i } );
	}
	sort( v.begin(), v.end() );
	reverse( v.begin(), v.end() );
	for ( int i = 1; i <= n; i ++ ) {
		while ( st.size() && a[ st.top() ] <= a[ i ] )
			st.pop();
		if ( !st.size() ) {
			mp[ i ] = 0;
		}
		else {
			mp[ i ] = st.top();
		}
		st.push( i );
		sum = 0;
		if ( mp[ i ] ) {
			sum = a[ i ] + a[ mp[ i ] ];
			upd( 1, 1, n, mp[ i ], sum );
		}
		num = 0;
		while ( v.size() && v.back().first <= i ) {
			gett( 1, 1, n, l[ v.back().second ], r[ v.back().second ] );
			cout << ( x[ v.back().second ] >= num ) << "\n";
			v.pop_back();
		}
	}
}

/*
9 1
5 2 2 8 3 4 8 9 10 
1 9 5
3 3
3 3

1 .. n
1 

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1293 ms 38004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 4416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -