This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lint;
typedef pair<int, lint> ants;
vector<ants> v;
int l, q;
int ants_kth[1005];
int main(){
scanf("%d %d",&l,&q);
int piv = 1;
for(int i=0; i<q; i++){
lint t;
int p;
scanf("%lld %d",&t,&p);
if(p == 1){
int pos, dx;
scanf("%d %d",&pos, &dx);
ants tx = ants(dx, pos - 1ll * dx * t);
int k = 1;
for(auto &i : v){
lint p = i.second + t * i.first;
p %= 2 * l;
p += 2 * l;
p %= 2 * l;
if(p > l) p = 2 * l - p;
if(p < pos) k++;
}
for(int i=1; i<piv; i++){
if(ants_kth[i] >= k){
ants_kth[i]++;
}
}
ants_kth[piv++] = k;
v.push_back(tx);
}
else{
int x;
scanf("%d",&x);
x = ants_kth[x];
vector<int> v2;
for(auto &i : v){
lint pos = i.second + t * i.first;
pos %= 2 * l;
pos += 2 * l;
pos %= 2 * l;
if(pos > l) v2.push_back(2 * l - pos);
else v2.push_back(pos);
}
sort(v2.begin(), v2.end());
printf("%d\n",v2[x - 1]);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |