답안 #498112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498112 2021-12-24T11:57:44 Z Ierus Meteors (POI11_met) C++17
74 / 100
4742 ms 65540 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>
//#define int long long
#pragma GCC optimization("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
 
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;
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    freopen ( "sum.in", "r", stdin )
*/
 
vector <int> vv[ 300002 ];
vector <int>  v[ 300002 ];
int L[ 300002 ], R[ 300002 ];
int an[ 300002 ];
long long t[ 1200002 ], p[ 1200002 ];
 
void pus( int v ) {
	if ( p[ v ] ) {
		p[ v + v ] += p[ v ];
		p[ v + v + 1 ] += p[ v ];
		t[ v + v ] += p[ v ];
		t[ v + v + 1 ] += p[ v ];
		p[ v ] = 0;
	}
}
 
void gett( int v, int tl, int tr, int pos ) {
	if ( tl > pos || tr < pos )
		return;
	if ( tl == tr ) {
		num += t[ v ];
		return;
	}
	pus( v );
	int mid = ( tl + tr ) / 2;
	if ( mid >= pos )
		gett( v + v, tl, mid, pos );
	if ( mid + 1 <= pos )
		gett( v + v + 1, mid + 1, tr, pos );
}
 
void upd( int v, int tl, int tr, int l, int r ) {
	if ( tl > r || tr < l )
		return;
	if ( tl >= l && tr <= r ) {
		t[ v ] += num;
		p[ v ] += num;
		return;
	}
	pus( v );
	int mid = ( tl + tr ) / 2;
	if ( mid >= l )
		upd( v + v, tl, mid, l, r );
	if ( mid + 1 <= r )
		upd( v + v + 1, mid + 1, tr, l, r );
}
 
main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for ( int i = 1; i <= m; i ++ ) {
    	int xx;cin >> xx;
    	vv[ xx ].push_back( i );
    }
    int b[ n + 1 ];
    for ( int i = 1; i <= n; i ++ ) {
    	cin >> b[ i ];
    }
    int q;
    cin >> q;
    int l[ q + 1 ], r[ q + 1 ], x[ q + 1 ];
    for ( int i = 1; i <= q; i ++ ) {
    	cin >> l[ i ] >> r[ i ] >> x[ i ];
    }
    for ( int i = 1; i <= n; i ++ )
    	L[ i ] = 1, R[ i ] = q + 1;
    ans = 1;
    int mid;
    while ( ans ) {
    	ans = 0;
    	memset(t, 0, sizeof(t));
    	memset(p, 0, sizeof(p));
    	
		for ( int i = 1; i <= n; i ++ ) {
//			cout << i << " - " << L[ i ] << " " << R[ i ] << "\n";
			if ( L[ i ] == R[ i ] )
				continue;
    		mid = ( L[ i ] + R[ i ] ) / 2;
    		v[ mid ].push_back( i ); 
    		ans = 1;
		}
		for ( int j = 1; j <= q; j ++ ) {
			num = x[ j ];
			if ( l[ j ] <= r[ j ] )	
				upd( 1, 1, m, l[ j ], r[ j ]  );
			else
				upd( 1, 1, m, 1, r[ j ] ), upd( 1, 1, m, l[ j ], m );
			if ( v[ j ].size() == 0 )
				continue;
			for ( auto i : v[ j ] ) {
				num = 0;
				for ( auto pos : vv[ i ] ) {
					gett( 1, 1, m, pos );
					if ( num >= b[ i ] ) {
						break;
					}
				}
//				cout << i << " - " << num << "\n";
				if ( num >= b[ i ] )
					R[ i ] = j;
				else
					L[ i ] = j + 1;
			}
			v[ j ].clear();
		}
		
	}
	for ( int i = 1; i <= n; i ++ ) {
		if ( L[ i ] <= q )
			cout << L[ i ] << "\n";
		else
			cout << "NIE\n";
	}
}

Compilation message

met.cpp:13: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   13 | #pragma GCC optimization("g", on)
      | 
met.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization("03")
      | 
met.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   16 | #pragma GCC optimization("unroll-loops")
      | 
met.cpp:17: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   17 | #pragma comment(linker, "/stack:200000000")
      | 
met.cpp:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 33100 KB Output is correct
2 Correct 40 ms 33248 KB Output is correct
3 Correct 39 ms 33192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 33248 KB Output is correct
2 Correct 47 ms 33240 KB Output is correct
3 Correct 51 ms 33260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 327 ms 34512 KB Output is correct
2 Correct 456 ms 36420 KB Output is correct
3 Correct 459 ms 36204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 399 ms 35548 KB Output is correct
2 Correct 450 ms 35700 KB Output is correct
3 Correct 493 ms 36628 KB Output is correct
4 Correct 120 ms 34960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 34956 KB Output is correct
2 Correct 298 ms 37112 KB Output is correct
3 Correct 202 ms 33804 KB Output is correct
4 Correct 444 ms 36696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 34124 KB Output is correct
2 Correct 410 ms 35576 KB Output is correct
3 Correct 393 ms 34344 KB Output is correct
4 Correct 481 ms 37728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4677 ms 50352 KB Output is correct
2 Correct 1090 ms 38040 KB Output is correct
3 Correct 965 ms 36576 KB Output is correct
4 Runtime error 4742 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Correct 4667 ms 48888 KB Output is correct
2 Correct 965 ms 38036 KB Output is correct
3 Correct 744 ms 35668 KB Output is correct
4 Runtime error 3592 ms 65540 KB Execution killed with signal 9