This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <list>
#define PII pair<int, int> 
using namespace std;
int main(){
	list<int> a;
	vector<PII> v;
	long long pt = 0;
	int n = 0;
	int L, Q;
	scanf("%d %d", &L, &Q);
	a.push_back(0);
	while (Q--){
		long long t;
		int p;
		scanf("%lld %d", &t, &p);
		long long mt = t - pt;
		pt = t;
		for (int i = 0; i < n; i++){
			v[i].first = (mt / L % 2 ? L - v[i].first : v[i].first)
				+ ((mt / L % 2 ? -1 : 1) * v[i].second * mt % L);
			v[i].second *= (mt / L % 2 ? -1 : 1);
			if (v[i].first < 0){
				v[i].first = -v[i].first;
				v[i].second = -v[i].second;
			}
			if (v[i].first > L){
				v[i].first = 2 * L - v[i].first;
				v[i].second = -v[i].second;
			}
		}
		sort(v.begin(), v.end());
		if (p == 1){
			int x, d, j = 0;
			scanf("%d %d", &x, &d);
			for (list<int>::iterator it = a.begin(); it != a.end(); it++, j++){
				if (j >= v.size() || v[j].first > x){
					a.insert(it, ++n);
					break;
				}
			}
			v.push_back(PII(x, d));
		}
		else{
			int i, j = 0;
			scanf("%d", &i);
			for (list<int>::iterator it = a.begin(); it != a.end(); it++, j++)
				if ((*it) == i)
					break;
			printf("%d\n", v[j].first);
		}
	}
	return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |