#include #include std::map valleys; int height_at(int x){ auto i1 = valleys.lower_bound(x); if(i1 != valleys.begin()) i1 --; auto i2 = valleys.lower_bound(x); if(i1 == valleys.end()) i1 --; int h1 = i1->second + std::abs(x - i1->first); int h2 = i2->second + std::abs(i2->first - x); return std::min(h1, h2); } int main(){ int N, Q; std::cin >> N >> Q; valleys[1] = 0; for(int q = 0, mode, x, c; q < Q; ++q){ std::cin >> mode >> x; if(mode == 1){ std::cout << height_at(x) << std::endl; } else{ std::cin >> c; if(c < height_at(x)){ valleys[x] = c; } } } }