제출 #666346

#제출 시각아이디문제언어결과실행 시간메모리
666346Kaztaev_AlisherSimple game (IZhO17_game)C++17
49 / 100
671 ms11960 KiB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;

const ll N = 1e6+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;

using namespace std;

ll a[N] , b[N] , x[N];
vector<int> v;
void solve(){
	int n , m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i > 1){
			int l = min(a[i] , a[i-1]);
			int r = max(a[i] , a[i-1]);
			x[l]++;
			x[r+1]--;
		}
	}	
	if(n <= 1000 && m <= 1000){
		while(m--){
			int tp ,pos , val;
			cin >> tp >> pos;
			if(tp == 2){
				int ans = 0;
				for(int i = 2; i <= n; i++){
					int mn = min(a[i] , a[i-1]);					
					int mx = max(a[i] , a[i-1]);
					if(mn <= pos && pos < mx) ans++;
					else if(mn < pos && pos <= mx) ans++;
				}
				cout << ans <<"\n";
			} else {
				cin >> val;
				a[pos] = val;	
			}
		}
		return;
	}
	for(int i = 1; i <= N-5; i++) x[i] += x[i-1];
	for(int i = 1; i <= m; i++){
		int tp;
		cin >> tp;
		if(tp == 2){
			int pos;
			cin >> pos;
			int ans = x[pos];
			for(int j : v){
				if(j-1 > 0){
					int mn = min(a[j] , a[j-1]);
					int mx = max(a[j] , a[j-1]);
					if(mn <= pos && pos <= mx) ans--;
					mn = min(a[j-1] , b[j]);
					mx = max(a[j-1] , b[j]);
					if(mn <= pos && pos <= mx) ans++;
				} 
				if(j+1 <= n){
					int mn = min(a[j] , a[j+1]);
					int mx = max(a[j] , a[j+1]);
					if(mn <= pos && pos <= mx) ans--;
					mn = min(a[j+1] , b[j]);
					mx = max(a[j+1] , b[j]);
					if(mn <= pos && pos <= mx) ans++;
				} 
			}	
			cout << ans <<"\n";
		} else {
			int pos , val;
			cin >> pos >> val;
			if(b[pos] == 0) v.pb(pos);
			b[pos] = val;
			if(v.sz() == 400){
				for(int j : v){
					a[j] = b[j];
					b[j] = 0;
				}
				for(int i = 1; i <= N-5; i++) x[i] = 0;
				for(int i = 2; i <= n; i++){
					int l = min(a[i] , a[i-1]);
					int r = max(a[i] , a[i-1]);
					x[l]++;
					x[r+1]--;
				}
				for(int i = 1; i <= N-5; i++) x[i] += x[i-1];
				v.cl();
			}	
		}
	}
}
signed main(){
	file("game");
	ios;
	solve();
	return 0;
}
/*
*/ 

컴파일 시 표준 에러 (stderr) 메시지

game.cpp: In function 'int main()':
game.cpp:17:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
game.cpp:122:2: note: in expansion of macro 'file'
  122 |  file("game");
      |  ^~~~
game.cpp:17:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
game.cpp:122:2: note: in expansion of macro 'file'
  122 |  file("game");
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...