Submission #673794

# Submission time Handle Problem Language Result Execution time Memory
673794 2022-12-22T04:16:39 Z smartmonky Weighting stones (IZhO11_stones) C++14
100 / 100
181 ms 4420 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N =  100001;
pair <int,int> t[N * 4];
int add[N * 4], mn;
int n;
void push(int v, int l, int r){
	if(l != r && add[v]){
		add[v * 2] += add[v];
		add[v * 2 + 1] += add[v];
	}
	t[v].ff += add[v];
		t[v].ss += add[v];
		add[v] = 0;
}
void update(int l, int r,int val, int v = 1, int tl = 1, int tr = n){
	push(v, tl, tr);
	if(tl > r || tr < l)
		return;
	if(tl >= l && tr <= r){
		add[v] += val;
		push(v, tl, tr);
		return;
	}
	int mid = (tl + tr) >> 1;
	update(l, r, val, v * 2, tl, mid);
	update(l, r, val, v * 2 + 1, mid + 1, tr);
	t[v].ff = min(t[v * 2].ff, t[v * 2 + 1].ff);
	t[v].ss = max(t[v * 2].ss, t[v * 2 + 1].ss);
}
pair <int,int> get(int l, int r, int v = 1, int tl = 1, int tr = n){
	push(v, tl, tr);
	if(tl > r || tr < l)
		return {1e9, -1e9};
	if(tl >= l && tr <= r){
		return t[v];
	}
	int mid = (tl + tr) >> 1;
	pair <int,int> left = get(l, r, v * 2, tl, mid);
	pair <int,int> right = get(l, r, v * 2 + 1, mid + 1, tr);
	return {min(left.ff, right.ff), max(left.ss, right.ss)};
}
main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		int r, s;
		cin >> r >> s;
		int dob = 1;
		if(s == 2)
			dob = -1;
		update(1, r, dob);
		pair <int,int> res = get(1, n);
		if(res.ss <= 0){
			cout << "<";
		}else if(res.ff >= 0){
			cout << ">";
		}else
			cout <<"?";
		cout << endl;
	}
}

Compilation message

stones.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main(){
      | ^~~~
stones.cpp: In function 'void fp(std::string)':
stones.cpp:12:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:12:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 15 ms 724 KB Output is correct
11 Correct 92 ms 2280 KB Output is correct
12 Correct 150 ms 4160 KB Output is correct
13 Correct 181 ms 4288 KB Output is correct
14 Correct 151 ms 4268 KB Output is correct
15 Correct 152 ms 4324 KB Output is correct
16 Correct 153 ms 4352 KB Output is correct
17 Correct 154 ms 4392 KB Output is correct
18 Correct 150 ms 4252 KB Output is correct
19 Correct 155 ms 4272 KB Output is correct
20 Correct 154 ms 4308 KB Output is correct
21 Correct 164 ms 4420 KB Output is correct
22 Correct 156 ms 4336 KB Output is correct
23 Correct 156 ms 4240 KB Output is correct
24 Correct 170 ms 4324 KB Output is correct
25 Correct 166 ms 4240 KB Output is correct