Submission #167004

#TimeUsernameProblemLanguageResultExecution timeMemory
167004abilTrading (IZhO13_trading)C++14
100 / 100
944 ms29072 KiB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (3e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int l[N], r[N], x[N], ans[N];
set<pair<int,int >> st, dt, cur_set;

void del(pair<int,int > pr){
	cur_set.erase(cur_set.find({l[pr.sc] - x[pr.sc], pr.sc}));
}
void add(pair<int,int > pr){
	dt.insert({r[pr.sc] + 1, pr.sc});
	cur_set.insert({l[pr.sc] - x[pr.sc], pr.sc});
}

int get(int pos){
	int res = 0;
	if(!cur_set.empty()){
		res = pos - cur_set.begin() -> fr;
	}
	return res;
}
main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1;i <= m; i++){
		scanf("%d%d%d", &l[i], &r[i], &x[i]);
		st.insert({l[i], i});
	}
	for(int i = 1;i <= n; i++){
		while(!dt.empty() && dt.begin() -> fr == i){
			del(*dt.begin());
			dt.erase(dt.begin());
		}
		while(!st.empty() && st.begin() -> fr == i){
			add(*st.begin());
			st.erase(st.begin());
		}
		printf("%d ", get(i));
	}
}

Compilation message (stderr)

trading.cpp:34:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
trading.cpp: In function 'int main()':
trading.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l[i], &r[i], &x[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...