text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int64_t DESPACITO = 2e18; const int INF = 2e9, MOD = 1e9 + 7; const int N = 2e5 + 5; struct Point { double x, y; }; int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); double a, b, c; Point start, end; cin >> a >> b >> c; cin >> start.x >> start.y; cin >> end.x >> end.y; array<Point, 2> from, to; from[0].x = start.x; from[0].y = -(a * start.x + c) / b; from[1].y = start.y; from[1].x = -(b * start.y + c) / a; to[0].x = end.x; to[0].y = -(a * end.x + c) / b; to[1].y = end.y; to[1].x = -(b * end.y + c) / a; auto distance = [&](const Point& p1, const Point& p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); }; auto manhattan = [&](const Point& p1, const Point& p2) { return abs(p1.x - p2.x) + abs(p1.y - p2.y); }; double ans = manhattan(start, end); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { double dist = 0; dist += manhattan(start, from[i]); dist += distance(from[i], to[j]); dist += manhattan(to[j], end); ans = min(ans, dist); } } cout.precision(9); cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; template <typename T> void vout(T x) { cout << x << endl; exit(0); } int gcd(int a, int b) { while (a && b) { if (a > b) a %= b; else b %= a; } return a + b; } const int inf = 1e9; const long long INF = 1e18; vector<pair<long double, long double> > v, v1; long double mn, a, b, c, gdjhdo, ghfdjhdo, x2, y2; long double rast(long double E, long double E1, long double E2, long double E3) { return sqrt(((E - E2) * (E - E2)) + ((E1 - E3) * (E1 - E3))); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> a >> b >> c >> gdjhdo >> ghfdjhdo >> x2 >> y2; mn = abs(gdjhdo - x2) + abs(ghfdjhdo - y2); long double x, y; x = gdjhdo; y = (-c - a * x) / b; v.push_back({x, y}); y = ghfdjhdo; x = (-c - b * y) / a; v.push_back({x, y}); x = x2; y = (-c - a * x) / b; v1.push_back({x, y}); y = y2; x = (-c - b * y) / a; v1.push_back({x, y}); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { mn = min(mn, rast(v[i].first, v[i].second, gdjhdo, ghfdjhdo) + rast(v1[j].first, v1[j].second, x2, y2) + rast(v[i].first, v[i].second, v1[j].first, v1[j].second)); } } cout << fixed << setprecision(10) << mn << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const int maxn = 4e5 + 5; const double inf = 2e9; double a, b, c; double _x1, _y1, _x2, _y2; double pointX(double y) { return ((-1 * b * y) - c) / a; } double pointY(double x) { return ((-1 * a * x) - c) / b; } double xdist(double x, double y) { double xp = pointX(y); return abs(x - xp); } double ydist(double x, double y) { double yp = pointY(x); return abs(y - yp); } double pythag(double xa, double ya, double xb, double yb) { double dx = abs(xa - xb); double dy = abs(ya - yb); return sqrt(dx * dx + dy * dy); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(9); cin >> a >> b >> c; cin >> _x1 >> _y1 >> _x2 >> _y2; double ans = abs(_x1 - _x2) + abs(_y1 - _y2); if (a != 0) { double xx = xdist(_x1, _y1) + pythag(pointX(_y1), _y1, pointX(_y2), _y2) + xdist(_x2, _y2); ans = min(ans, xx); } if (b != 0) { double yy = ydist(_x1, _y1) + pythag(_x1, pointY(_x1), _x2, pointY(_x2)) + ydist(_x2, _y2); ans = min(ans, yy); } if (a != 0 && b != 0) { double xy = xdist(_x1, _y1) + pythag(pointX(_y1), _y1, _x2, pointY(_x2)) + ydist(_x2, _y2); ans = min(ans, xy); double yx = ydist(_x1, _y1) + pythag(_x1, pointY(_x1), pointX(_y2), _y2) + xdist(_x2, _y2); ans = min(ans, yx); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct point { long double x, y; point(long double val1, long double val2) { x = val1; y = val2; } point() { x = 0; y = 0; } }; struct line { long double a, b, c; line() { a = 0; b = 0; c = 0; } line(point A, point B) { a = (B.y - A.y); b = (A.x - B.x); c = ((-1) * (a * A.x + b * A.y)); } line(long double val1, long double val2, long double val3) { a = val1; b = val2; c = val3; } }; struct circle { point o; long double r; circle() { o = point(0, 0); r = 1; } circle(point p, long double val) { o = p; r = val; } circle(long double x, long double y, long double val) { o.x = x; o.y = y; r = val; } }; void swap(point& a, point& b) { swap(a.x, b.x); swap(a.y, b.y); } void swap(line a, line b) { swap(a.a, b.a); swap(a.b, b.b); swap(a.c, b.c); } void swap(circle& a, circle& b) { swap(a.o, b.o); swap(a.r, b.r); } point operator+(point a, point b) { point c(a.x + b.x, a.y + b.y); return c; } point operator-(point a, point b) { point c(a.x - b.x, a.y - b.y); return c; } long double operator*(point a, point b) { return a.x * b.x + a.y * b.y; } long double operator^(point a, point b) { return a.x * b.y - a.y * b.x; } bool operator==(point a, point b) { return a.x == b.x && a.y == b.y; } bool operator==(line a, line b) { return a.a == b.a && a.b == b.b && a.c == b.c; } bool operator==(circle a, circle b) { return a.o == b.o && a.r == b.r; } istream& operator>>(istream& stream, line& a) { stream >> a.a >> a.b >> a.c; return stream; } istream& operator>>(istream& stream, point& a) { stream >> a.x >> a.y; return stream; } istream& operator>>(istream& stream, circle& a) { stream >> a.o >> a.r; return stream; } ostream& operator<<(ostream& stream, point& a) { stream << a.x << " " << a.y << " "; return stream; } ostream& operator<<(ostream& stream, line& a) { stream << a.a << " " << a.b << " " << a.c; return stream; } ostream& operator<<(ostream& stream, circle& a) { stream << a.o << a.r; return stream; } long double angle(point a, point b, point c) { return atan2((a - b) ^ (c - b), (a - b) * (c - b)); } long double twSpace(point a, point b, point c) { return (a - b) ^ (c - b); } long double dist(point a, point b) { long double f = a.x - b.x, s = a.y - b.y; return sqrt(f * f + s * s); } long double lineDist(point a, point b, point c) { return (long double)(abs(twSpace(a, b, c))) / dist(b, c); } long double rayDist(point a, point b, point c) { if (((c - b) * (a - b)) < 0) { return dist(a, b); } return lineDist(a, b, c); } long double segmentDist(point a, point b, point c) { if (((c - b) * (a - b)) < 0) { return dist(a, b); } if (((b - c) * (a - c)) < 0) { return dist(a, c); } return lineDist(a, b, c); } bool insideAngle(point a, point o, point b, point p) { if (((b - o) ^ (a - o)) < 0) { swap(a, b); } if (((b - o) ^ (p - o)) >= 0 && ((a - o) ^ (p - o)) <= 0) { return true; } return false; } bool rayCross(point a, point b, point c, point d) { if (((b - a) ^ (c - a)) == 0) { return (rayDist(c, a, b) == 0) || (rayDist(a, c, d) == 0); } return insideAngle(a, c, c + b - a, d) && ((b - a) ^ (d - c)) != 0; } bool segmentCross(point a, point b, point c, point d) { return (rayCross(a, b, c, d)) && (rayCross(b, a, c, d)) && (rayCross(a, b, d, c)) && (rayCross(b, a, d, c)); } long double segmentSegmentDist(point a, point b, point c, point d) { if (segmentCross(a, b, c, d)) { return 0.0; } return min(min(segmentDist(a, c, d), segmentDist(b, c, d)), min(segmentDist(c, a, b), segmentDist(d, a, b))); } bool segmentRayCross(point a, point b, point c, point d) { return rayCross(a, b, c, d) && rayCross(b, a, c, d); } long double segmentRayDist(point a, point b, point c, point d) { if (segmentRayCross(a, b, c, d)) { return 0.0; } return min(min(rayDist(a, c, d), rayDist(b, c, d)), segmentDist(c, a, b)); } bool segmentLineCross(point a, point b, point c, point d) { return segmentRayCross(a, b, c, d) || segmentRayCross(a, b, d, c); } long double segmentLineDist(point a, point b, point c, point d) { if (segmentLineCross(a, b, c, d)) { return 0.0; } return min(lineDist(a, c, d), lineDist(b, c, d)); } long double rayRayDist(point a, point b, point c, point d) { if (rayCross(a, b, c, d)) { return 0.0; } return min(rayDist(a, c, d), rayDist(c, a, b)); } bool rayLineCross(point a, point b, point c, point d) { return rayCross(a, b, c, d) || rayCross(a, b, d, c); } long double rayLineDist(point a, point b, point c, point d) { if (rayLineCross(a, b, c, d)) { return 0.0; } return lineDist(a, c, d); } bool lineLineCross(point a, point b, point c, point d) { return rayLineCross(a, b, c, d) || rayLineCross(b, a, c, d); } long double lineLineDist(point a, point b, point c, point d) { if (lineLineCross(a, b, c, d)) { return 0.0; } return lineDist(a, c, d); } long double lineDist(point a, line t) { return (long double)abs(t.a * a.x + t.b * a.y + t.c) / sqrt((long double)(t.a * t.a + t.b * t.b)); } point cross(line f, line s) { long double ansx, ansy; if (s.a == 0 || s.b == 0) { swap(f, s); } if (f.a == 0) { ansy = (-1) * (f.c / f.b); ansx = (-1) * (s.b * ansy + s.c) / s.a; } else if (f.b == 0) { ansx = (-1) * f.c / f.a; ansy = (-1) * (ansx * s.a + s.c) / s.b; } else { ansy = (f.c * s.a - f.a * s.c) / (f.a * s.b - f.b * s.a); ansx = (f.c * s.b - s.c * f.b) / (s.a * f.b - f.a * s.b); } point a(ansx, ansy); return a; } long double value(point p, line l) { return p.x * l.a + p.y * l.b + l.c; } void l() { while (true) { }; } line perp(line l, point p) { point norm(l.a, l.b); line ans(p, p + norm); return ans; } point medianCross(point a, point b, point c) { point m1((a.x + b.x) / 2, (a.y + b.y) / 2), m2((a.x + c.x) / 2, (a.y + c.y) / 2); line cm1(c, m1), bm2(b, m2); point ans = cross(cm1, bm2); return ans; } point turn(point a, long double alpha) { long double x = a.x, y = a.y; point ans(x * cos(alpha) - y * sin(alpha), y * cos(alpha) + x * sin(alpha)); return ans; } line bisector(point a, point b, point c) { long double alpha = angle(a, b, c); line ans(b, b + turn(a - b, alpha / 2)); point temp = turn(a - b, alpha / 2); return ans; } point incenter(point a, point b, point c) { line f = bisector(a, b, c), s = bisector(b, c, a); return cross(f, s); } point middle(point a, point b) { point ans((a.x + b.x) / 2, (a.y + b.y) / 2); return ans; } point center(point a, point b, point c) { point m1 = middle(a, b), m2 = middle(b, c); line ab(a, b), bc(b, c); line f = perp(ab, m1), s = perp(bc, m2); point ans = cross(f, s); return ans; } point changeSize(point a, long double d) { long double temp = sqrt(a.x * a.x + a.y * a.y); a.x *= (d / temp); a.y *= (d / temp); return a; } long double sq(long double a) { return a * a; } vector<point> cross(line l, circle c) { point t = c.o; l.c += l.a * c.o.x + l.b * c.o.y; vector<point> ans; point O(0, 0); line k = perp(l, O); point temp = cross(k, l); if (dist(temp, O) > c.r) { return ans; } if (dist(temp, O) == c.r) { ans.push_back(temp + c.o); return ans; } long double dist = sqrt(sq(c.r) - (sq(l.c)) / (sq(l.a) + sq(l.b))); point step((-1) * l.b, l.a); ans.push_back(c.o + temp + changeSize(step, dist)); ans.push_back(c.o + temp - changeSize(step, dist)); return ans; } vector<point> cross(circle a, circle b) { if (sq(a.o.x - b.o.x) + sq(a.o.y - b.o.y) == sq(a.r + b.r)) { vector<point> ans; ans.push_back(a.o + changeSize(b.o - a.o, a.r)); return ans; } if (sq(a.o.x - b.o.x) + sq(a.o.y - b.o.y) == sq(a.r - b.r)) { if (b.r > a.r) { swap(a, b); } vector<point> ans; ans.push_back(a.o + changeSize(b.o - a.o, a.r)); return ans; } if (sq(a.o.x - b.o.x) + sq(a.o.y - b.o.y) > sq(a.r + b.r) || sq(a.o.x - b.o.x) + sq(a.o.y - b.o.y) < sq(a.r - b.r)) { vector<point> ans; return ans; } line temp(2 * a.o.x - 2 * b.o.x, 2 * a.o.y - 2 * b.o.y, sq(b.o.x) + sq(b.o.y) - sq(a.o.x) - sq(a.o.y) - sq(b.r) + sq(a.r)); return cross(temp, a); } vector<point> findTouch(point p, circle c) { vector<point> ans; if (sq(c.o.x - p.x) + sq(c.o.y - p.y) < sq(c.r)) { return ans; } if (sq(c.o.x - p.x) + sq(c.o.y - p.y) == sq(c.r)) { ans.push_back(p); return ans; } long double a1 = c.o.x, b1 = c.o.y, a2 = p.x, b2 = p.y, r = c.r; line key(2 * a1 - 2 * a2, 2 * b1 - 2 * b2, sq(a2) + sq(b2) - sq(a1) - sq(b1) + 2 * sq(r) - sq(a1 - a2) - sq(b1 - b2)); return cross(key, c); } line makeBiss(point x, point y, point z) { point Y = z - x; long double b = sqrt(Y.x * Y.x + Y.y * Y.y); Y = point(Y.x / b, Y.y / b); point X = y - x; long double a = sqrt(X.x * X.x + X.y * X.y); X = point(X.x / a, X.y / a); point m = X + Y; return (line(x, m + x)); } bool iz_perp(point a, point b, point c) { a = a - c; b = b - c; if (a.x * b.x + a.y * b.y == 0) return true; return false; } bool iz_on_line(line a, point x) { return a.a * x.x + a.b * x.y + a.c == 0; } signed main() { cout.precision(20); line a; point b, c; cin >> a >> b >> c; long double ans = abs((b.x - c.x)) + abs((b.y - c.y)); point b1 = cross(a, line(1, 0, -b.x)); point b2 = cross(a, line(0, 1, -b.y)); point c1 = cross(a, line(1, 0, -c.x)); point c2 = cross(a, line(0, 1, -c.y)); ans = min(ans, dist(b, b1) + dist(b1, c1) + dist(c1, c)); ans = min(ans, dist(b, b1) + dist(b1, c2) + dist(c2, c)); ans = min(ans, dist(b, b2) + dist(b2, c1) + dist(c1, c)); ans = min(ans, dist(b, b2) + dist(b2, c2) + dist(c2, c)); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; struct Line { double a, b, c; void read() { cin >> a >> b >> c; } }; struct Vector { double x, y; void read() { cin >> x >> y; } }; Vector cl(Line l1, Line l2) { double x = (l1.c * l2.b - l2.c * l1.b) / (l2.a * l1.b - l1.a * l2.b); double y = (l2.c * l1.a - l1.c * l2.a) / (l1.b * l2.a - l2.b * l1.a); return Vector{x, y}; } double dist(Vector a, Vector b) { double dist = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); return dist; } double const q = 1e-7; int main() { Line line; line.read(); Vector A, B; A.read(), B.read(); vector<double> ans; ans.push_back(abs(A.x - B.x) + abs(A.y - B.y)); if (line.a != 0 && line.b != 0) { Line ax{1, 0, -A.x}; Line ay{0, 1, -A.y}; Line bx{1, 0, -B.x}; Line by{0, 1, -B.y}; Vector M = cl(ay, line); Vector N = cl(ax, line); Vector K = cl(by, line); Vector E = cl(bx, line); double AM = dist(A, M); double AN = dist(A, N); double BE = dist(B, E); double BK = dist(B, K); double MK = dist(M, K); double ME = dist(M, E); double NK = dist(N, K); double NE = dist(N, E); ans.push_back(AM + MK + BK); ans.push_back(AM + ME + BE); ans.push_back(AN + NK + BK); ans.push_back(AN + NE + BE); } double ans_ = ans[0]; for (auto i : ans) { if (ans_ > i + q) { ans_ = i; } } cout.precision(7); cout << fixed << ans_; }
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long double a, b, c; long double ycal(long long x) { return (-c - a * x) / b; } long double xcal(long long y) { return (-c - b * y) / a; } long double sq(long double a) { return a * a; } long double di(pair<long double, long double> p1, pair<long double, long double> p2) { return sqrtl(sq(p1.first - p2.first) + sq(p1.second - p2.second)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long double x1, y1, x2, y2; cin >> a >> b >> c >> x1 >> y1 >> x2 >> y2; long double dis = abs(x2 - x1) + abs(y2 - y1); if (a == 0 || b == 0) { cout << fixed << setprecision(10) << dis << '\n'; return 0; } vector<pair<long double, long double>> v1(2), v2(2), v(4); v1[0] = {x1, ycal(x1)}; v2[0] = {x2, ycal(x2)}; v1[1] = {xcal(y1), y1}; v2[1] = {xcal(y2), y2}; v[0] = v1[0]; v[1] = v1[1]; v[2] = v2[0]; v[3] = v2[1]; sort(v.begin(), v.end()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); if (v[0] == v1[0] && v[1] == v1[1]) { dis = di({x1, y1}, v[1]) + di(v[1], v[2]) + di(v[2], {x2, y2}); } else if (v[0] == v2[0] && v[1] == v2[1]) { dis = di({x2, y2}, v[1]) + di(v[1], v[2]) + di(v[2], {x1, y1}); } cout << fixed << setprecision(10) << dis << '\n'; }
#include <bits/stdc++.h> using namespace std; long long a, b, c; double findx(long long y) { double num = -1 * ((double)b * (double)y + (double)c); return num / a; } double findy(long long x) { double num = -1 * ((double)a * (double)x + (double)c); return num / b; } double dist(pair<double, double> p1, pair<double, double> p2) { double a2 = pow(abs(p1.first - p2.first), 2.0), b2 = pow(abs(p1.second - p2.second), 2.0); return pow(a2 + b2, 0.5); } int32_t main() { cin >> a >> b >> c; long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; long long ans = abs(x2 - x1) + abs(y2 - y1); double dans = (double)ans; if (a == 0 || b == 0) { cout << ans << endl; return 0; } double ax = findx(y1), ay = findy(x1), bx = findx(y2), by = findy(x2); bool changed = false; double cand1 = abs((double)x1 - ax) + dist({ax, (double)y1}, {(double)x2, by}) + abs(by - (double)y2); if (cand1 < dans) { changed = true; dans = cand1; } double cand2 = abs((double)x1 - ax) + dist({ax, (double)y1}, {bx, (double)y2}) + abs(bx - (double)x2); if (cand2 < dans) { changed = true; dans = cand2; } double cand3 = abs((double)y1 - ay) + dist({(double)x1, ay}, {(double)x2, by}) + abs(by - (double)y2); if (cand3 < dans) { changed = true; dans = cand3; } double cand4 = abs((double)y1 - ay) + dist({(double)x1, ay}, {bx, (double)y2}) + abs(bx - (double)x2); if (cand4 < dans) { changed = true; dans = cand4; } if (changed) { printf("%.10f\n", dans); } else { cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; struct point { long double x; long double y; }; long double est(point A, point B) { return sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cout.precision(9); long double a, b, c; cin >> a >> b >> c; point A, B, C; cin >> A.x >> A.y >> B.x >> B.y; C.x = A.x; C.y = B.y; long double crab; crab = est(A, C) + est(B, C); point alx, aly, blx, bly; alx.x = -(b * A.y + c) / a; alx.y = A.y; aly.x = A.x; aly.y = -(a * A.x + c) / b; blx.x = -(b * B.y + c) / a; blx.y = B.y; bly.x = B.x; bly.y = -(a * B.x + c) / b; long double calxblx = est(alx, blx) + est(A, alx) + est(B, blx); long double calyblx = est(aly, blx) + est(A, aly) + est(B, blx); long double calxbly = est(alx, bly) + est(A, alx) + est(B, bly); long double calybly = est(aly, bly) + est(A, aly) + est(B, bly); cout << fixed << min(crab, min(calxblx, min(calxbly, min(calyblx, calybly)))); }
#include <bits/stdc++.h> using namespace std; inline long long int max(long long int a, long long int b, long long int c) { return max(max(a, b), c); } inline long long int min(long long int a, long long int b, long long int c) { return min(min(a, b), c); } inline long long int max(long long int a, long long int b) { return (a > b) ? a : b; } inline long long int min(long long int a, long long int b) { return (a < b) ? a : b; } inline long long int add(long long int x, long long int y, long long int mod_) { return (x + y >= mod_) ? x + y - mod_ : x + y; } inline long long int mul(long long int x, long long int y, long long int mod_) { return ((x % mod_) * 1LL * (y % mod_)) % mod_; } long long int power(long long int a, long long int n) { long long int p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } long long int powm(long long int a, long long int n, long long int mod_) { long long int p = 1; while (n) { if (n % 2) { p = mul(p, a, mod_); } n >>= 1; a = mul(a, a, mod_); } return p % mod_; } long long int powi(long long int a, long long int mod_) { return powm(a, mod_ - 2, mod_); } double dis(double x1, double y1, double x2, double y2) { double s = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); s = sqrtl(s); return s; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cout << setprecision(15); long long int mn, mx; long long int n, m, t, k, i, j, sum = 0, flag = 0, cnt = 0; long long int x = 0, y = 0, z, l, r, q; int TC = 1; while (TC--) { double a, b, c; cin >> a >> b >> c; double x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; double v1, h1, v2, h2; if (a == 0 or b == 0) { double mn = abs(x1 - x2) + abs(y1 - y2); cout << mn; return 0; } v1 = b ? 1.0 * (-c - a * x1) / b - y1 : 1e12; h1 = a ? 1.0 * (-c - b * y1) / a - x1 : 1e12; v2 = b ? 1.0 * (-c - a * x2) / b - y2 : 1e12; h2 = a ? 1.0 * (-c - b * y2) / a - x2 : 1e12; double mn; mn = abs(x1 - x2) + abs(y1 - y2); double d = abs(v1) + abs(v2) + dis(x1, v1 + y1, x2, v2 + y2); mn = min(mn, d); d = abs(v1) + abs(h2) + dis(x1, v1 + y1, h2 + x2, y2); mn = min(mn, d); d = abs(h1) + abs(h2) + dis(h1 + x1, y1, h2 + x2, y2); mn = min(mn, d); d = abs(h1) + abs(v2) + dis(h1 + x1, y1, x2, v2 + y2); mn = min(mn, d); cout << mn; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long double EPS = 1e-7; struct Point { long double x, y; Point() {} Point(long double x, long double y) { this->x = x; this->y = y; } }; long double a, b, c; Point s, f; long double get_dist(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } long double get_dk_dist(Point a, Point b) { return abs(a.x - b.x) + abs(a.y - b.y); } long double go(Point p1, Point p2) { return get_dk_dist(s, p1) + get_dist(p1, p2) + get_dk_dist(p2, f); } long double get_x(long long p) { if (a == 0) { return INF; } return -(b * p + c) / a; } long double get_y(long long p) { if (b == 0) { return INF; } return -(a * p + c) / b; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> a >> b >> c; cin >> s.x >> s.y >> f.x >> f.y; long double ans = get_dk_dist(s, f); Point sp[] = {Point(get_x(s.y), s.y), Point(s.x, get_y(s.x))}; Point fp[] = {Point(get_x(f.y), f.y), Point(f.x, get_y(f.x))}; if (sp[0].x != INF) { if (fp[0].x != INF) { ans = min(ans, go(sp[0], fp[0])); } if (fp[1].y != INF) { ans = min(ans, go(sp[0], fp[1])); } } if (sp[1].y != INF) { if (fp[0].x != INF) { ans = min(ans, go(sp[1], fp[0])); } if (fp[1].y != INF) { ans = min(ans, go(sp[1], fp[1])); } } cout << setprecision(30) << fixed << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; long double mabs(long double k) { if (k < 0) return -k; return k; } struct Point { long double x, y; long double distman(const Point& p) const { long double dx = p.x - this->x, dy = p.y - this->y; return mabs(dx) + mabs(dy); } long double disteuc(const Point& p) const { long double dx = p.x - this->x, dy = p.y - this->y; return sqrt(dx * dx + dy * dy); } Point() {} Point(long double _x, long double _y) : x(_x), y(_y) {} }; long double evalx(long double a, long double b, long double c, long double x) { return (-a * x - c) / b; } long double evaly(long double a, long double b, long double c, long double y) { return (-b * y - c) / a; } pair<long double, Point> distver(const Point& P, long double a, long double b, long double c) { return {mabs(P.y - evalx(a, b, c, P.x)), Point(P.x, evalx(a, b, c, P.x))}; } pair<long double, Point> disthor(const Point& P, long double a, long double b, long double c) { return {mabs(P.x - evaly(a, b, c, P.y)), Point(evaly(a, b, c, P.y), P.y)}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long double a, b, c; cin >> a >> b >> c; Point A, B; cin >> A.x >> A.y >> B.x >> B.y; long double ans = A.distman(B); if (mabs(a) < EPS) { } else if (mabs(b) < EPS) { } else { pair<long double, Point> distvera = distver(A, a, b, c), distverb = distver(B, a, b, c), disthora = disthor(A, a, b, c), disthorb = disthor(B, a, b, c); ans = min(ans, distvera.first + distvera.second.disteuc(distverb.second) + distverb.first); ans = min(ans, distvera.first + distvera.second.disteuc(disthorb.second) + disthorb.first); ans = min(ans, disthora.first + disthora.second.disteuc(distverb.second) + distverb.first); ans = min(ans, disthora.first + disthora.second.disteuc(disthorb.second) + disthorb.first); } cout << fixed << setprecision(10) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; struct pt { double first, second; pt() {} pt(double first, double second) : first(first), second(second) {} }; double dist(pt a, pt b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); } int main() { cout.precision(20); double a, b, c; pt A, B; cin >> a >> b >> c >> A.first >> A.second >> B.first >> B.second; double ans = fabs(A.first - B.first) + fabs(A.second - B.second); if (fabs(a) < eps || fabs(b) < eps) { cout << ans; return 0; } vector<pair<pt, pt>> trace; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { trace.push_back(pair<pt, pt>()); trace.back().first = i ? pt(A.first, (a * A.first + c) / -b) : pt((b * A.second + c) / -a, A.second); trace.back().second = j ? pt(B.first, (a * B.first + c) / -b) : pt((b * B.second + c) / -a, B.second); } } for (pair<pt, pt>& f : trace) ans = min(ans, dist(A, f.first) + dist(f.first, f.second) + dist(f.second, B)); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int visited[200001] = {0}; map<long long, vector<long long> > m; vector<vector<long long> > v; double dis(double a, double b, double c, double d) { return sqrt((a - c) * (a - c) + (b - d) * (b - d)); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long i, a, b, c, x1, y1, x2, y2; cin >> a >> b >> c; cin >> x1 >> y1 >> x2 >> y2; double xa, ya, xb, yb, d; vector<double> res; d = abs(x2 - x1) + abs(y2 - y1); res.push_back(d); xa = -(b * y1 + c) * 1.0 / a; ya = -(a * x1 + c) * 1.0 / b; xb = -(b * y2 + c) * 1.0 / a; yb = -(a * x2 + c) * 1.0 / b; res.push_back(dis(x1, y1, xa, y1) + dis(xa, y1, xb, y2) + dis(xb, y2, x2, y2)); res.push_back(dis(x1, y1, xa, y1) + dis(xa, y1, x2, yb) + dis(x2, yb, x2, y2)); res.push_back(dis(x1, y1, x1, ya) + dis(x1, ya, xb, y2) + dis(xb, y2, x2, y2)); res.push_back(dis(x1, y1, x1, ya) + dis(x1, ya, x2, yb) + dis(x2, yb, x2, y2)); sort(res.begin(), res.end()); cout << setprecision(15) << res[0]; return 0; }
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3; for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; } int NumDigits(int x) { return ( x < 10 ? 1 : (x < 100 ? 2 : (x < 1000 ? 3 : (x < 10000 ? 4 : (x < 100000 ? 5 : (x < 1000000 ? 6 : (x < 10000000 ? 7 : (x < 100000000 ? 8 : (x < 1000000000 ? 9 : 10))))))))); } inline void boostIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline long long int Pow10(int x) { if (x == 0) return 1; if (x == 1) return 10; if (x == 2) return 100; if (x == 3) return 1000; if (x == 4) return 10000; if (x == 5) return 100000; if (x == 6) return 1000000; if (x == 7) return 10000000; if (x == 8) return 100000000; if (x == 9) return 1000000000; if (x == 10) return 10000000000; } long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } int main() { boostIO(); cout.precision(10); long double a, b, c; cin >> a >> b >> c; long double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; long double x3, y3, x4, y4; long double One = abs(x1 - (-c - y1 * b) / a) + abs(x2 - (-c - y2 * b) / a); x3 = (-c - y1 * b) / a; y3 = (-c - x3 * a) / b; x4 = (-c - y2 * b) / a; y4 = (-c - x4 * a) / b; One += sqrt((x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4)); long double Two = abs(x1 - (-c - y1 * b) / a) + abs(y2 - (-c - x2 * a) / b); x3 = (-c - y1 * b) / a; y3 = (-c - x3 * a) / b; y4 = (-c - x2 * a) / b; x4 = (-c - y4 * b) / a; Two += sqrt((x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4)); long double Three = abs(y1 - (-c - x1 * a) / b) + abs(x2 - (-c - y2 * b) / a); y3 = (-c - x1 * a) / b; x3 = (-c - y3 * b) / a; x4 = (-c - y2 * b) / a; y4 = (-c - x4 * a) / b; Three += sqrt((x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4)); long double Four = abs(y1 - (-c - x1 * a) / b) + abs(y2 - (-c - x2 * a) / b); y3 = (-c - x1 * a) / b; x3 = (-c - y3 * b) / a; y4 = (-c - x2 * a) / b; x4 = (-c - y4 * b) / a; Four += sqrt((x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4)); long double Five = abs(x1 - x2) + abs(y1 - y2); cout << min(Five, min(min(One, Two), min(Three, Four))) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long a, b, c, x1, y1, x2, y2; cin >> a >> b >> c >> x1 >> y1 >> x2 >> y2; long double ans = abs(x2 - x1) + abs(y2 - y1); if (a && b) { auto f = [&](long long a, long long b, long long x1, long long y1, long long x2, long long y2) { long double ay = (long double)(-c - a * x1) / b, bx = (long double)(-c - b * y2) / a, by = (long double)(-c - a * x2) / b; ans = min({abs(y1 - ay) + abs(x2 - bx) + hypot(x1 - bx, y2 - ay), abs(y1 - ay) + abs(y2 - by) + hypot(x2 - x1, ay - by), ans}); }; f(a, b, x1, y1, x2, y2); f(b, a, y1, x1, y2, x2); } cout << fixed << setprecision(9) << ans; }
#include <bits/stdc++.h> using namespace std; double a, b, c; double l1(pair<double, double> x, pair<double, double> b) { return abs(x.first - b.first) + abs(x.second - b.second); } double l2(pair<double, double> x, pair<double, double> b) { return sqrt((x.first - b.first) * (x.first - b.first) + (x.second - b.second) * (x.second - b.second)); } double y(int x) { if (b == 0) return INT_MIN; return -(a * x + c) / b; } double x(int y) { if (a == 0) return INT_MIN; return -(b * y + c) / a; } bool inRange(double x, double s, double e) { return min(s, e) <= x && x <= max(e, s); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; cin >> a >> b >> c; pair<int, int> st, ed; cin >> st.first >> st.second >> ed.first >> ed.second; double ans = l1(st, ed); vector<pair<double, double>> pts; if (inRange(y(st.first), st.second, ed.second)) { pts.push_back(make_pair(st.first, y(st.first))); } if (inRange(y(ed.first), st.second, ed.second)) { pts.push_back(make_pair(ed.first, y(ed.first))); } if (inRange(x(st.second), st.first, ed.first)) { pts.push_back(make_pair(x(st.second), st.second)); } if (inRange(x(ed.second), st.first, ed.first)) { pts.push_back(make_pair(x(ed.second), ed.second)); } for (int i = 0; i < (int)(pts.size()); i++) { for (int j = i + 1; j < pts.size(); j++) { ans = min(ans, l1(pts[i], st) + l1(pts[j], ed) + l2(pts[i], pts[j])); ans = min(ans, l1(pts[j], st) + l1(pts[i], ed) + l2(pts[i], pts[j])); } } printf("%0.11f", ans); }
#include <bits/stdc++.h> using namespace std; long double d(long double x1, long double y1, long double x2, long double y2) { return abs(x1 - x2) + abs(y1 - y2); } long double d2(long double x1, long double y1, long double x2, long double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long double a, b, c, x1, y1, x2, y2, v1, v2, h1, h2, ans, pv1x, pv1y, pv2x, pv2y, ph1x, ph1y, ph2x, ph2y; cin >> a >> b >> c >> x1 >> y1 >> x2 >> y2; ans = d(x1, y1, x2, y2); pv1x = x1, pv2x = x2, ph1y = y1, ph2y = y2; if (b) { pv1y = -(a * x1 + c) / b; pv2y = -(a * x2 + c) / b; } else { pv1y = 1e15; pv2y = -1e15; } if (a) { ph1x = -(b * y1 + c) / a; ph2x = -(b * y2 + c) / a; } else { ph1x = 1e15; ph2x = -1e15; } ans = min(ans, d(x1, y1, pv1x, pv1y) + min(d2(pv1x, pv1y, pv2x, pv2y) + d(x2, y2, pv2x, pv2y), d2(pv1x, pv1y, ph2x, ph2y) + d(x2, y2, ph2x, ph2y))); ans = min(ans, d(x1, y1, ph1x, ph1y) + min(d2(ph1x, ph1y, pv2x, pv2y) + d(x2, y2, pv2x, pv2y), d2(ph1x, ph1y, ph2x, ph2y) + d(x2, y2, ph2x, ph2y))); cout << fixed << setprecision(7) << ans; }
#include <bits/stdc++.h> const double eps = 1e-9; double a, b, c, nx, mx, ny, my, ans; long long ax, ay, bx, by; int main() { std::cin >> a >> b >> c >> ax >> ay >> bx >> by; ans = std::abs(ax - bx) + std::abs(ay - by); if ((a < eps && a > -eps) || (b < eps && b > -eps)) { printf("%.7lf\n", ans); return 0; } nx = -b / a, mx = -c / a, ny = -a / b, my = -c / b; ans = std::min( ans, std::abs(ay - (ny * ax + my)) + std::abs(by - (ny * bx + my)) + sqrt((ax - bx) * (ax - bx) + ((ny * ax + my) - (ny * bx + my)) * ((ny * ax + my) - (ny * bx + my)))); ans = std::min( ans, std::abs(ax - (nx * ay + mx)) + std::abs(bx - (nx * by + mx)) + sqrt((ay - by) * (ay - by) + ((nx * ay + mx) - (nx * by + mx)) * ((nx * ay + mx) - (nx * by + mx)))); ans = std::min(ans, std::abs(ay - (ny * ax + my)) + std::abs(bx - (nx * by + mx)) + sqrt((ax - (nx * by + mx)) * (ax - (nx * by + mx)) + ((ny * ax + my) - by) * ((ny * ax + my) - by))); ans = std::min(ans, std::abs(ax - (nx * ay + mx)) + std::abs(by - (ny * bx + my)) + sqrt((ay - (ny * bx + my)) * (ay - (ny * bx + my)) + ((nx * ay + mx) - bx) * ((nx * ay + mx) - bx))); printf("%.7lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double a, b, c; double xa, ya, xb, yb; struct node { double x, y; }; vector<node> po[2]; double dis(node a, node b, int id) { if (id == 1) return abs(a.x - b.x) + abs(a.y - b.y); else return hypot(a.x - b.x, a.y - b.y); } void deal(double x, int id, int a_b) { if (id == 1) { double y = (-c - a * x) / b; node p; p.x = x; p.y = y; po[a_b].push_back(p); } else { double y = (-c - b * x) / a; node p; p.x = y; p.y = x; po[a_b].push_back(p); } } int main() { cin >> a >> b >> c; cin >> xa >> ya >> xb >> yb; double ans = abs(xa - xb) + abs(ya - yb); if (a == 0 || b == 0) { printf("%0.10lf\n", ans); return 0; } deal(xa, 1, 0); deal(ya, 2, 0); deal(xb, 1, 1); deal(yb, 2, 1); double now; node A = {xa, ya}; node B = {xb, yb}; for (auto i : po[0]) { for (auto j : po[1]) { now = dis(A, i, 1) + dis(i, j, 2) + dis(j, B, 1); ans = min(ans, now); } } printf("%0.10lf", ans); }
#include <bits/stdc++.h> using namespace std; long double eu_dist(double x1, double y1, double x2, double y2) { long double sqdis = (x1 - x2) * (x1 - x2); sqdis += (y1 - y2) * (y1 - y2); return sqrt(sqdis); } void play() { long long a, b, c; cin >> a >> b >> c; long double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; long double distx1 = -b * y1 - c; if (a == 0) { distx1 = 2.5e18; } else { distx1 /= a; } long double disty1 = -a * x1 - c; if (b == 0) { disty1 = 2.5e18; } else { disty1 /= b; } long double distx2 = -b * y2 - c; if (a == 0) { distx2 = 2.5e18; } else { distx2 /= a; } long double disty2 = -a * x2 - c; if (b == 0) { disty2 = 2.5e18; } else { disty2 /= b; } 42; long double mindist = abs(x1 - x2) + abs(y1 - y2); if (distx1 < 2e18 && disty2 < 2e18) { mindist = min(mindist, abs(x1 - distx1) + abs(y2 - disty2) + eu_dist(distx1, y1, x2, disty2)); } if (disty1 < 2e18 && distx2 < 2e18) { mindist = min(mindist, abs(y1 - disty1) + abs(x2 - distx2) + eu_dist(x1, disty1, distx2, y2)); } if (distx1 < 2e18 && distx2 < 2e18) { mindist = min(mindist, abs(x1 - distx1) + abs(x2 - distx2) + eu_dist(distx1, y1, distx2, y2)); } if (disty1 < 2e18 && disty2 < 2e18) { mindist = min(mindist, abs(y1 - disty1) + abs(y2 - disty2) + eu_dist(x1, disty1, x2, disty2)); } printf("%.9Lf\n", mindist); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; while (t--) { play(); } return 0; }
#include <bits/stdc++.h> using namespace std; long double a, b, c, x, y, z, t, s = 1, X = 0, Y = 0, Z = 0, T = 0, xx, yy, zz, tt, u; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15) << fixed; cin >> a >> b >> c >> x >> y >> z >> t; if (y == t) { cout << abs(x - z); return 0; } if (x == z) { cout << abs(y - t); return 0; } if (a == 0 || b == 0) { cout << abs(x - z) + abs(y - t); return 0; } if (a < 0) s = -s; if (b < 0) s = -s; if (x > z) s = -s; if (y > t) s = -s; if (s == 1) { cout << abs(x - z) + abs(y - t); return 0; } if (x < z) { swap(x, z); swap(y, t); } xx = (-c - a * x) / b; yy = (-c - b * y) / a; zz = (-c - a * z) / b; tt = (-c - b * t) / a; if (y > t) { if (xx <= y && xx >= t) X = 1; if (zz <= y && zz >= t) Z = 1; if (yy <= x && yy >= z) Y = 1; if (tt <= x && tt >= z) T = 1; if (X + Y + Z + T < 2) { cout << x + y - z - t; return 0; } if (X == 1 && Z == 1) { u = (long double)sqrt((xx - zz) * (xx - zz) + (x - z) * (x - z)); cout << setprecision(15) << fixed << y - t - xx + zz + u; return 0; } if (Y == 1 && T == 1) { u = (long double)sqrt((yy - tt) * (yy - tt) + (y - t) * (y - t)); cout << setprecision(15) << fixed << x - z - yy + tt + u; return 0; } if (X == 1 && T == 1) { u = (long double)sqrt((xx - t) * (xx - t) + (x - tt) * (x - tt)); cout << setprecision(15) << fixed << y - xx + tt - z + u; return 0; } if (Y == 1 && Z == 1) { u = (long double)sqrt((yy - z) * (yy - z) + (y - zz) * (y - zz)); cout << setprecision(15) << fixed << x - yy + zz - t + u; return 0; } } else { if (xx <= t && xx >= y) X = 1; if (zz <= t && zz >= y) Z = 1; if (yy <= x && yy >= z) Y = 1; if (tt <= x && tt >= z) T = 1; if (X + Y + Z + T < 2) { cout << x + t - z - y; return 0; } if (X == 1 && Z == 1) { u = (long double)sqrt((xx - zz) * (xx - zz) + (x - z) * (x - z)); cout << setprecision(15) << fixed << t - y - zz + xx + u; return 0; } if (Y == 1 && T == 1) { u = (long double)sqrt((yy - tt) * (yy - tt) + (y - t) * (y - t)); cout << setprecision(15) << fixed << x - z - yy + tt + u; return 0; } if (X == 1 && T == 1) { u = (long double)sqrt((xx - t) * (xx - t) + (x - tt) * (x - tt)); cout << setprecision(15) << fixed << xx - y + tt - z + u; return 0; } if (Y == 1 && Z == 1) { u = (long double)sqrt((yy - z) * (yy - z) + (y - zz) * (y - zz)); cout << setprecision(15) << fixed << x - yy + t - zz + u; return 0; } } }
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } vector<long long> b_v; void bin(unsigned long long n) { if (n > 1) bin(n >> 1); b_v.emplace_back(n & 1); } long long isPowerof2(long long x) { return (x && !(x & x - 1)); } double a, b, c, p1, q1, p2, q2; double dist(double xx1, double yy1, double xx2, double yy2) { double tmp = (xx1 - xx2) * (xx1 - xx2) + (yy1 - yy2) * (yy1 - yy2); return (double)(sqrt(tmp)); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ostream_iterator<long long> output(cout, " "); cin >> a >> b >> c; cin >> p1 >> q1 >> p2 >> q2; double ans = abs(p1 - p2) + abs(q1 - q2); if (a && b) { pair<double, double> pp1, pp2, qq1, qq2; pp1 = make_pair(p1, ((-1.0) * (c + p1 * a) / b)); pp2 = make_pair(((-1.0) * (c + b * q1) / a), q1); qq1 = make_pair(p2, ((-1.0) * (c + p2 * a) / b)); qq2 = make_pair(((-1.0) * (c + b * q2) / a), q2); ans = min(ans, dist(pp1.first, pp1.second, qq1.first, qq1.second) + dist(p1, q1, pp1.first, pp1.second) + dist(p2, q2, qq1.first, qq1.second)); ans = min(ans, dist(pp1.first, pp1.second, qq2.first, qq2.second) + dist(p1, q1, pp1.first, pp1.second) + dist(p2, q2, qq2.first, qq2.second)); ans = min(ans, dist(pp2.first, pp2.second, qq1.first, qq1.second) + dist(p1, q1, pp2.first, pp2.second) + dist(p2, q2, qq1.first, qq1.second)); ans = min(ans, dist(pp2.first, pp2.second, qq2.first, qq2.second) + dist(p1, q1, pp2.first, pp2.second) + dist(p2, q2, qq2.first, qq2.second)); } cout << fixed << setprecision(15) << ans; return 0; }
#include <bits/stdc++.h> const double INF = 1e18, eps = 1e-18; double a, b, c, x_1, y_1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, ans; double sqr(double x) { return x * x; } double dis(double x_1, double y_1, double x2, double y2) { return sqrt(sqr(x2 - x_1) + sqr(y_1 - y2)); } int main() { scanf("%lf%lf%lf%lf%lf%lf%lf", &a, &b, &c, &x_1, &y_1, &x6, &y6); if (std::abs(a - 0) > eps && std::abs(b - 0) > eps) y2 = y_1, x2 = (-b * y2 - c) / a; else y2 = x2 = INF; if (std::abs(a - 0) > eps && std::abs(b - 0) > eps) x3 = x_1, y3 = (-a * x3 - c) / b; else x3 = y3 = INF; if (std::abs(a - 0) > eps && std::abs(b - 0) > eps) y4 = y6, x4 = (-b * y4 - c) / a; else x4 = y4 = INF; if (std::abs(a - 0) > eps && std::abs(b - 0) > eps) x5 = x6, y5 = (-a * x5 - c) / b; else x5 = y5 = INF; ans = std::min( std::min( std::min( dis(x_1, y_1, x2, y2) + dis(x2, y2, x4, y4) + dis(x4, y4, x6, y6), dis(x_1, y_1, x2, y2) + dis(x2, y2, x5, y5) + dis(x5, y5, x6, y6)), dis(x_1, y_1, x3, y3) + dis(x3, y3, x4, y4) + dis(x4, y4, x6, y6)), dis(x_1, y_1, x3, y3) + dis(x3, y3, x5, y5) + dis(x5, y5, x6, y6)); ans = std::min(ans, std::abs(x6 - x_1) + std::abs(y6 - y_1)); printf("%.10lf", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const double inf = 1e18; int read() { int s = 0; char c = getchar(), lc = '+'; while (c < '0' || '9' < c) lc = c, c = getchar(); while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar(); return lc == '-' ? -s : s; } void write(int x) { if (x < 0) { putchar('-'); x = -x; } if (x < 10) putchar(x + '0'); else { write(x / 10); putchar(x % 10 + '0'); } } void print(int x, char c = '\n') { write(x); putchar(c); } double sqr(double x) { return x * x; } struct point { double x, y; } p[10]; struct line { double a, b, c; point X(double x) { point ret; ret.x = x; ret.y = -(a * x + c) / b; return ret; } point Y(double y) { point ret; ret.x = -(b * y + c) / a; ret.y = y; return ret; } } l; double dis(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } double f[10][10]; signed main() { double a = read(), b = read(), c = read(); double x1 = read(), y1 = read(), x2 = read(), y2 = read(); l.a = a; l.b = b; l.c = c; p[0].x = x1; p[0].y = y1; p[5].x = x2; p[5].y = y2; p[1] = l.X(x1); p[2] = l.Y(y1); p[3] = l.X(x2); p[4] = l.Y(y2); for (int i = 0; i <= 5; i++) for (int j = 0; j <= 5; j++) f[i][j] = inf; f[0][5] = fabs(x1 - x2) + fabs(y1 - y2); f[0][1] = dis(p[0], p[1]); f[0][2] = dis(p[0], p[2]); f[3][5] = dis(p[3], p[5]); f[4][5] = dis(p[4], p[5]); for (int i = 1; i <= 4; i++) for (int j = 1; j <= 4; j++) f[i][j] = dis(p[i], p[j]); for (int k = 0; k <= 5; k++) for (int i = 0; i <= 5; i++) for (int j = 0; j <= 5; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]); printf("%.10lf", f[0][5]); return 0; }
#include <bits/stdc++.h> const long long MXN = 1e5 + 12; const double eps = 1e-10; const double pi = acos(-1.0); const long long OO = 1e18 + 1; const int MNN = 1e5 + 1; const int MOD = 1e9 + 7; using namespace std; double a, b, c, x1, fkjalskdf, x2, y2, dist = OO; vector<pair<double, double> > s, e; double get_dist(double x1, double fkjalskdf, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (fkjalskdf - y2) * (fkjalskdf - y2)); } int main() { ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); ; cin >> a >> b >> c; cin >> x1 >> fkjalskdf >> x2 >> y2; if (b != 0) { s.push_back(make_pair(x1, -(a * x1 + c) / b)); e.push_back(make_pair(x2, -(a * x2 + c) / b)); } if (a != 0) { s.push_back(make_pair(-(fkjalskdf * b + c) / a, fkjalskdf)); e.push_back(make_pair(-(y2 * b + c) / a, y2)); } for (int i = 0; i < s.size(); i++) { for (int j = 0; j < e.size(); j++) { dist = min(get_dist(x1, fkjalskdf, s[i].first, s[i].second) + get_dist(s[i].first, s[i].second, e[j].first, e[j].second) + get_dist(e[j].first, e[j].second, x2, y2), dist); } } cout << fixed << setprecision(6) << min(dist, abs(x1 - x2) + abs(fkjalskdf - y2)); return 0; }
#include <bits/stdc++.h> using namespace std; double rast(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b, c; cin >> a >> b >> c; long long x1, x2, y2, y1; cin >> x1 >> y1 >> x2 >> y2; if (a == 0 || b == 0) { cout << abs(x1 - x2) + abs(y1 - y2); return 0; } double fx1 = 1.0 * (-a * x1 - c) / b; double fx2 = 1.0 * (-a * x2 - c) / b; double gy1 = 1.0 * (-b * y1 - c) / a; double gy2 = 1.0 * (-b * y2 - c) / a; double ans = 0.0000000000000000; double r1 = rast(gy1, y1, gy2, y2) + abs(gy1 - x1) + abs(gy2 - x2); double r2 = rast(gy2, y2, x1, fx1) + abs(gy2 - x2) + abs(fx1 - y1); double r3 = rast(x1, fx1, x2, fx2) + abs(fx1 - y1) + abs(fx2 - y2); double r4 = rast(gy1, y1, x2, fx2) + abs(gy1 - x1) + abs(fx2 - y2); double r5 = 1.0 * abs(x1 - x2) + abs(y1 - y2) * 1.0; cout << fixed << setprecision(20) << min(r1, min(r2, min(r3, min(r4, r5)))); }
#include <bits/stdc++.h> #pragma GCC optimize(3, "Ofast", "inline") using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const long long maxn = (long long)3e5 + 5; const long long mod = 998244353; const long long inf = 0x3f3f3f3f; const double eps = 1e-10; long long T = 1; double dis(pair<double, double> a, pair<double, double> b) { return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2)); } void solve() { double ans, ans1, ans2, ans3, ans4; ans = ans1 = ans2 = ans3 = ans4 = 1e18; double a, b, c; pair<double, double> p1, p2; cin >> a >> b >> c >> p1.first >> p1.second >> p2.first >> p2.second; ans = fabs(p1.first - p2.first) + fabs(p1.second - p2.second); if (fabs(a) < eps) { pair<double, double> q1 = {p1.first, -c / b}; pair<double, double> q2 = {p2.first, -c / b}; ans1 = dis(p1, q1) + dis(q1, q2) + dis(q2, p2); } else if (fabs(b) < eps) { pair<double, double> q1 = {-c / a, p1.second}; pair<double, double> q2 = {-c / a, p2.second}; ans2 = fabs(p1.first - q1.first) + dis(q1, q2) + fabs(p2.first - q2.first); } else { pair<double, double> q1, q2, q3, q4; q1 = make_pair(p1.first, -(a * p1.first + c) / b); q3 = make_pair(-(b * p1.second + c) / a, p1.second); q2 = make_pair(p2.first, -(a * p2.first + c) / b); q4 = make_pair(-(b * p2.second + c) / a, p2.second); ans1 = dis(p1, q1) + dis(q1, q2) + dis(q2, p2); ans2 = dis(p1, q1) + dis(q1, q4) + dis(q4, p2); ans3 = dis(p1, q3) + dis(q3, q2) + dis(q2, p2); ans4 = dis(p1, q3) + dis(q3, q4) + dis(q4, p2); } cout << fixed << setprecision(10) << min(ans, min(ans1, min(ans2, min(ans3, ans4)))); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m, l; cin >> n >> m >> l; vector<long long> arr(n); long long count = 0; for (int i = 0; i < n; ++i) { cin >> arr[i]; if (arr[i] > l && (i == 0 || arr[i - 1] <= l) && (i == n - 1 || arr[i + 1] <= l)) { count++; } } for (int i = 0; i < m; ++i) { int x, pos, y; cin >> x; if (x) { cin >> pos >> y; if (arr[pos - 1] <= l && arr[pos - 1] + y > l) { if (pos - 2 >= 0 && arr[pos - 2] > l && pos < n && arr[pos] > l) { count--; } else if ((pos - 1 == 0 || arr[pos - 2] <= l) && (pos == n || arr[pos] <= l)) { count++; } } arr[pos - 1] += y; } else { cout << count << endl; } } } int main() { ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(9); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, Q, l; cin >> N >> Q >> l; int a[N + 2]; for (int i = 1; i <= N; ++i) cin >> a[i]; bool cutted[N + 2]; fill(cutted, cutted + N + 2, false); for (int i = 1; i <= N; ++i) { if (a[i] > l) cutted[i] = true; } int ans = 0; for (int i = 1; i <= N; ++i) { if (cutted[i] && !cutted[i + 1]) ++ans; } for (int q = 0; q < Q; ++q) { int t; cin >> t; if (t == 0) { cout << ans << "\n"; } else { int x, d; cin >> x >> d; if (cutted[x]) continue; a[x] += d; if (a[x] > l) { cutted[x] = true; if (cutted[x - 1] && cutted[x + 1]) { --ans; } else if (!cutted[x - 1] && !cutted[x + 1]) { ++ans; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; long long a[maxn]; int main() { ios_base::sync_with_stdio(0); int n, m; long long l; cin >> n >> m >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; } int res = 0; for (int i = 1; i <= n; i++) { if (a[i] > l) { if (i == 1 || a[i - 1] <= l) res++; } } while (m--) { int t; cin >> t; if (t == 0) { cout << res << "\n"; continue; } int p; long long d; cin >> p >> d; long long pval = a[p]; a[p] += d; if (pval > l) continue; if (pval + d <= l) continue; int c = 0; if (p > 1 && a[p - 1] > l) c++; if (p < n && a[p + 1] > l) c++; res += 1 - c; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 100500; mt19937 gen(time(NULL)); template <typename T = int> inline T read() { T val = 0, sign = 1; char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') sign = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) val = val * 10 + ch - '0'; return sign * val; } void precalc() {} void solve() { int n = read(), m = read(), l = read(); vector<long long> arr(n); for (int i = 0; i < n; i++) { arr[i] = read(); } int res = 0; vector<int> bad; for (int i = 0; i < n; i++) if (arr[i] > l) { if (bad.size() && bad.back() == i - 1) bad.pop_back(); bad.push_back(i); } int basic_res = bad.size(); for (int i = 0; i < m; i++) { int t = read(); if (t == 0) { cout << basic_res << '\n'; continue; } int j = read(), x = read(); j--; if (arr[j] > l) continue; arr[j] += x; if (arr[j] <= l) continue; if (j == 0) { if (arr[j + 1] <= l) { basic_res++; } } else if (j == n - 1) { if (arr[j - 1] <= l) { basic_res++; } } else { if (arr[j - 1] > l && arr[j + 1] > l) basic_res--; else if (arr[j - 1] <= l && arr[j + 1] <= l) basic_res++; } } } signed main() { int t = 1; precalc(); while (t--) { clock_t z = clock(); solve(); fprintf(stderr, "Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC), fflush(stderr); } }
#include <bits/stdc++.h> using namespace std; struct Snm { long long r; long long f; }; vector<Snm> snm; long long get(long long v) { if (snm[v].f == v) return v; snm[v].f = get(snm[v].f); return snm[v].f; } void un(long long a, long long b) { if (snm[a].r < snm[b].r) swap(a, b); snm[b].f = a; if (snm[a].r == snm[b].r) snm[a].r++; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, l; cin >> n >> m >> l; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i = 0; i < n; i++) snm.push_back({-1, -1}); long long cmp = 0; for (long long i = 0; i < n; i++) { if (v[i] > l) { snm[i] = {1, i}; cmp++; if (i > 0 && snm[i - 1].f != -1) { un(get(i - 1), get(i)); cmp--; } } } for (long long i = 0; i < m; i++) { long long tp; cin >> tp; if (tp == 0) cout << cmp << endl; else { long long p, d; cin >> p >> d; v[p - 1] += d; if (v[p - 1] > l) { if (snm[p - 1].r == -1) { snm[p - 1] = {1, p - 1}; cmp++; if (p - 2 >= 0 && snm[p - 2].f != -1) { un(get(p - 2), get(p - 1)); cmp--; } if (p < n && snm[p].f != -1) { un(get(p), get(p - 1)); cmp--; } } } } } }
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) using namespace std; const int N = 1e5 + 5; long long a[N]; int main() { int n, m, l; scanf("%d %d %d", &n, &m, &l); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); int cnt = 0; for (int i = 1; i <= n; i++) { if (a[i] > l) { if (i == 1 || a[i - 1] <= l) cnt++; } } int ty, p, d; while (m--) { scanf("%d", &ty); if (ty == 0) printf("%d\n", cnt); else { scanf("%d %d", &p, &d); if (a[p] <= l) { a[p] += d; if (a[p] > l) { if (p == 1 || a[p - 1] <= l) { if (p == n || a[p + 1] <= l) cnt++; } if (p != 1 && p != n && a[p - 1] > l && a[p + 1] > l) cnt--; } } else a[p] += d; } } return 0; }
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; long long Power(long long a, long long b) { if (b == 0) return 1; long long p = Power(a, b / 2); p = (p * p); if (b & 1) { p = (p * a); } return p; } long long Gcd(long long a, long long b) { if (b == 0) return a; if (a < b) return Gcd(b, a); return Gcd(b, a % b); } void Solve() { int n, m; long long l; cin >> n >> m >> l; vector<long long> arr(n), seg(n, -1); for (int i = 0; i < n; i++) cin >> arr[i]; int curr = 0, prev = -1; for (int i = 0; i < n; i++) { if (arr[i] > l) { seg[i] = 0; if (prev == -1) { curr++; } prev = 0; } else { prev = -1; seg[i] = -1; } } while (m--) { int t; cin >> t; if (t == 0) { cout << curr << '\n'; } else { int p; long long d; cin >> p >> d; p--; arr[p] += d; if (seg[p] == -1 && arr[p] > l) { seg[p] = 0; if (p == 0) { if (p + 1 < n && seg[p + 1] == -1) { curr++; } else if (n == 1) { curr++; } } else if (p == n - 1) { if (p - 1 >= 0 && seg[p - 1] == -1) { curr++; } else if (n == 1) { curr++; } } else { if (seg[p - 1] == 0 && seg[p + 1] == 0) { curr--; } else if (seg[p - 1] == -1 && seg[p + 1] == -1) { curr++; } } } } } } int main() { int t = 1; while (t--) { Solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int a[100001]; bool flag[100002]; int main() { int n, m, l; cin >> n >> m >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > l) { flag[i] = true; } } int ans = 0; for (int i = 1; i <= n; i++) { if (flag[i]) { if (!flag[i + 1]) { ans++; } } } while (m--) { int type; cin >> type; if (type == 0) { cout << ans << endl; } else { int p, d; cin >> p >> d; a[p] += d; if (a[p] > l) { if (!flag[p]) { if (flag[p + 1] && flag[p - 1]) { ans--; } if (!flag[p + 1] && !flag[p - 1]) { ans++; } } flag[p] = true; } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 10; const int MOD = (int)1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, l; long long ans = 0; cin >> n >> m >> l; vector<long long> v(n + 2); for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i <= n; i++) if (v[i] > l && v[i - 1] <= l) ans++; while (m--) { int t; cin >> t; if (!t) cout << ans << "\n"; else { int p, d; cin >> p >> d; if (v[p] <= l && v[p] + d > l) { if (v[p - 1] <= l && v[p + 1] <= l) ans++; if (v[p - 1] > l && v[p + 1] > l) ans--; } v[p] += d; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, l, A[100000], p, d, t; cin.tie(0); cin >> n >> m >> l; for (int i = 0; i < n; ++i) cin >> A[i]; int c = 0; for (int i = 0; i < n;) { if (A[i] > l) { c++; while (i < n && A[i] > l) ++i; } else ++i; } for (int i = 0; i < m; ++i) { cin >> t; if (t == 0) cout << c << '\n'; else { cin >> p >> d; p--; if (A[p] <= l && A[p] + d > l) { if (p > 0 && p < n - 1 && A[p - 1] > l && A[p + 1] > l) c--; if ((p == 0 || A[p - 1] <= l) && (p == n - 1 || A[p + 1] <= l)) c++; } A[p] += d; } } }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("-O2") template <typename tp> void in(tp &dig) { char ch = getchar(); dig = 0; long long flag = 0; while (!isdigit(ch)) { if (ch == '-') flag = 1; ch = getchar(); } while (isdigit(ch)) dig = dig * 10 + ch - '0', ch = getchar(); if (flag) dig = -dig; } template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } const int LIM = 2e5 + 5, MOD = 1e9 + 7; int n, m, l, qwer, t, x, y; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> qwer >> l; int h[n + 1], m[n + 2]; for (int i = 0; i < n; i++) { cin >> h[i + 1]; } int ans = 0; m[0] = 0; m[n + 1] = 0; for (int i = 1; i < n + 1; i++) { if (h[i] <= l) { m[i] = 0; continue; } if (m[i - 1] == 0) { ans++; m[i] = 1; } else { m[i] = 1; } } for (int i = 0; i < qwer; i++) { cin >> x; if (x == 0) cout << ans << "\n"; else { cin >> y >> t; if (m[y] == 1) continue; else if (h[y] + t <= l) h[y] += t; else { int r = m[y - 1] + m[y + 1]; if (r == 2) ans--; else if (r == 0) ans++; m[y] = 1; } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXINT = 2147483647; const long long MAXLL = 9223372036854775807LL; const int MAX = 400000; long long n, m, l, a[MAX], pos, col, x, y, z; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> m >> l; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] > l) { for (int j = i; j < n; j++) { if (a[j] <= l) break; pos = j; } col++; i = pos; } } for (int i = 0; i < m; i++) { cin >> x; if (x == 0) cout << col << '\n'; else { cin >> y >> z; if (y == n) { if (a[n - 2] <= l && a[n - 1] <= l && a[n - 1] + z > l) col++; } else if (y == 1) { if (a[1] <= l && a[0] <= l && a[0] + z > l) col++; } else { y--; if (a[y - 1] <= l && a[y] <= l && a[y] + z > l && a[y + 1] <= l) col++; if (a[y - 1] > l && a[y] <= l && a[y] + z > l && a[y + 1] > l) col--; y++; } a[y - 1] += z; } } return 0; }
#include <bits/stdc++.h> int main() { long long int n, m, l, i, v = 0, p = 0, d, e; scanf("%lld %lld %lld", &n, &m, &l); long long int a[n], t[m]; for (i = 0; i < n; i = i + 1) { scanf("%lld", &a[i]); if (a[i] > l) { a[i] = 0; } } for (i = 0; i < n; i = i + 1) { if (a[i] == 0) { if (v == 0) { v = 1; p = p + 1; } } else { v = 0; } } for (i = 0; i < m; i = i + 1) { scanf("%lld", &t[i]); if (t[i] == 0) { printf("%lld\n", p); } else { scanf("%lld %lld", &d, &e); if (a[d - 1] != 0) { a[d - 1] = a[d - 1] + e; if (a[d - 1] > l) { if (d - 1 == 0 && a[d] != 0) { p = p + 1; } else if (d - 1 == 0 && a[d] == 0) { p = p + 0; } else if (d - 1 == n - 1 && a[d - 2] == 0) { p = p + 0; } else if (d - 1 == n - 1 && a[d - 2] != 0) { p = p + 1; } else if (a[d - 2] == 0 && a[d] == 0) { p = p - 1; } else if (a[d - 2] != 0 && a[d] != 0) { p = p + 1; } a[d - 1] = 0; } } } } }
#include <bits/stdc++.h> const long long md = 998244353; const int Inf = 1e9; const long long Inf64 = 1e18; const long long MaxN = 2e5 + 10; const long long MaxM = 11; const long double eps = 1e-15; const long long dx[4] = {0, 1, 0, -1}; const long long dy[4] = {1, 0, -1, 0}; const long long ddx[4] = {1, 1, -1, -1}; const long long ddy[4] = {1, -1, 1, -1}; const long double Pi = acos(-1); using namespace std; long long gcd(long long a, long long b) { while (a) { b %= a; swap(a, b); } return b; } long long gcdex(long long a, long long mod = md) { long long g = mod, r = a, x = 0, y = 1; while (r != 0) { long long q = g / r; g %= r; swap(g, r); x -= q * y; swap(x, y); } return x < 0 ? x + mod : x; } long long binpow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) { res *= a; res %= md; } a *= a; a %= md; n >>= 1; } return res % md; } long long par[MaxN]; long long Kl; void MS(long long i) { par[i] = i; } long long FS(long long a) { if (par[a] == a) return a; else return par[a] = FS(par[a]); } void US(long long a, long long b) { a = FS(a); b = FS(b); if (a != b) { Kl--; par[b] = a; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cout << fixed, cout.precision(10); long long N, L, Q; cin >> N >> Q >> L; vector<long long> Mt(N); for (int i = 0; i < N; i++) { cin >> Mt[i]; if (Mt[i] > L) MS(i), Kl++; if (i != 0) { if (Mt[i - 1] > L && Mt[i] > L) { US(i - 1, i); } } } while (Q--) { long long a; cin >> a; if (!a) { cout << Kl << '\n'; } else { long long b, c; cin >> b >> c; b--; if (Mt[b] > L) { Mt[b] += c; } else { Mt[b] += c; if (Mt[b] > L) { Kl++; MS(b); if (b > 0 && Mt[b - 1] > L) { US(b - 1, b); } if (b < N - 1 && Mt[b + 1] > L) { US(b + 1, b); } } } } } cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long cul, que, len, x, y, z, trig = 0, old = -1; map<long long, long long> m, an; map<long long, long long>::iterator it; bool vis[1000000]; void primaryjob() { memset((vis), (false), sizeof((vis))); ; for (long long int i = (long long int)1; i <= cul; i++) { if (m[i] > len) { vis[i] = true; } } old = 0; for (long long int i = (long long int)1; i <= cul; i++) { if (vis[i]) { old++; while (vis[i + 1] == vis[i]) { i++; } } } } int main() { scanf("%lld %lld %lld", &cul, &que, &len); for (long long int i = (long long int)0; i < cul; i++) { scanf("%lld", &x); m[i + 1] = x; } primaryjob(); for (long long int i = (long long int)0; i < que; i++) { scanf("%lld", &x); if (x) { scanf("%lld %lld", &y, &z); trig = 0; if (m[y] > len) { trig = 1; } m[y] = m[y] + z; if (trig and m[y] > len) trig = 0; else if (!trig and m[y] > len) trig = 1; if (trig) { vis[y] = true; if (vis[y - 1] and vis[y + 1]) old--; if (!vis[y - 1] and !vis[y + 1]) old++; } } else { printf("%lld\n", old); } } }
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, i, e, f, g, n, m, k, l, A[100005], fix[100005], ans; int main() { cin >> n >> m >> l; for (i = 1; i <= n; i++) { cin >> A[i]; if (A[i] > l) { fix[i] = 1; if (fix[i - 1] == 1 && fix[i + 1] == 1) ans--; else if (fix[i - 1] == 1 || fix[i + 1] == 1) continue; else ans++; } } for (i = 1; i <= m; i++) { cin >> a; if (a == 1) { cin >> b >> c; if (A[b] > l) continue; A[b] += c; if (A[b] > l) { fix[b] = 1; if (fix[b - 1] == 1 && fix[b + 1] == 1) ans--; else if (fix[b - 1] == 1 || fix[b + 1] == 1) continue; else ans++; } } else cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; bool dp[200011]; long long n, m, l, p, d; long long a[200011]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > l) dp[i] = 1; } long long ans = 0; for (int i = 1; i <= n; i++) { if (dp[i - 1] == 0 && dp[i]) ans++; } bool b; while (m--) { cin >> b; if (b) { cin >> p >> d; if (dp[p]) continue; else a[p] += d; if (a[p] > l) dp[p] = 1; if (dp[p] && dp[p - 1] == 0 && dp[p + 1] == 0) ans++; else if (dp[p] && dp[p - 1] && dp[p + 1]) ans--; } else { cout << ans << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int mxn = 5e5 + 123; const int inf = 1e9; const int mod = 1e9 + 7; long long a[mxn], n, p[mxn]; vector<long long> g[555], x; bool used[555]; int main() { long long n, m, l; cin >> n >> m >> l; for (long long i = 1; i <= n; i++) { cin >> a[i]; } long long r = 0; a[n + 1] = 0; for (long long i = 1; i <= n + 1; i++) { if (a[i] > l) r++; else { if (r > 0) p[1]++; r = 0; } } for (long long i = 1; i <= m; i++) { long long x; cin >> x; if (x == 1) { long long y, z; cin >> y >> z; a[y] += z; if (a[y] > l && a[y] - z <= l) { if (a[y - 1] > l && a[y + 1] > l) p[1]--; else if (a[y - 1] <= l && a[y + 1] <= l && a[y] - z <= l) p[1]++; } } else { cout << p[1] << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, l; cin >> n >> m >> l; int a[n], c = 0, p = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] <= l) { if (p == 0) continue; c++; p = 0; } else p = 1; } if (p) c++; int t, d; for (int i = 0; i < m; i++) { cin >> t; if (t == 0) cout << c << "\n"; else { cin >> p >> d; p--; if (a[p] > l) continue; else { a[p] += d; if (a[p] <= l) continue; if (p == 0) { if (n == 1) c++; else if (a[1] <= l) c++; } else if (p == n - 1) { if (a[n - 2] <= l) c++; } else { if (a[p - 1] > l && a[p + 1] > l) c--; if (a[p - 1] <= l && a[p + 1] <= l) c++; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[100005]; int main() { int n, m, l; cin >> n >> m >> l; for (int i = 1; i <= n; i++) { scanf("%lld", a + i); } int now = 0; for (int i = 1; i <= n; i++) { if (a[i] > l) { if (a[i - 1] > l) continue; now++; } } int op; int p, d; while (m--) { scanf("%d", &op); if (op == 0) { printf("%d\n", now); } else { scanf("%d%d", &p, &d); if (a[p] > l) { a[p] += d; } else { a[p] += d; if (a[p] > l) { if (a[p - 1] > l && a[p + 1] > l) { now--; } else if (a[p - 1] > l) { ; } else if (a[p + 1] > l) { ; } else { now++; } } else { continue; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> a; long long n, m, l; cin >> n >> m >> l; a.resize(n, 0); long long cnt = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { if (a[i] <= l && a[i - 1] > l) cnt++; } if (a[n - 1] > l) cnt++; for (int j = 0; j < m; j++) { int t; cin >> t; if (t) { int p, d; cin >> p >> d; p--; a[p] += d; int i = p; if (a[i] > l && a[i] - d <= l && (i > 0 && a[i - 1] > l) && (i < n - 1 && a[i + 1] > l)) { cnt--; } else { if (a[i] > l && a[i] - d <= l && (i > 0 && a[i - 1] <= l || i == 0) && (i < n - 1 && a[i + 1] <= l || i == n - 1)) { cnt++; } } } else { cout << cnt << '\n'; } } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, l, a[100001], i, t = 0, p, d, k, w; cin >> n >> m >> l; for (i = 0; i < n; i++) cin >> a[i]; if (a[0] > l) t++; for (i = 1; i < n; i++) { if (a[i] > l && a[i - 1] <= l) t++; } for (i = 0; i < m; i++) { cin >> k; if (k == 0) { cout << t << endl; } else { cin >> p >> d; w = a[p - 1]; a[p - 1] += d; if (p == 1) { if (a[p] <= l && a[p - 1] > l && w <= l) t++; } else if (p == n) { if (a[p - 2] <= l && a[p - 1] > l && w <= l) t++; } else { if (a[p - 1] > l && a[p - 2] <= l && a[p] <= l && w <= l) t++; else if (a[p - 1] > l && a[p - 2] > l && a[p] > l && w <= l) t--; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int p[1000005]; int fnd(int x) { return p[x] = p[x] == x ? x : fnd(p[x]); } void unn(int x, int y) { p[fnd(y)] = fnd(x); } long long a[100005]; int chk[100005]; int main() { int n, m, l; scanf("%d%d%d", &n, &m, &l); for (int i = 1; i <= n; i++) p[i] = i; int cnt = 0; for (int i = 1; i <= n; i++) { scanf("%I64d", a + i); if (a[i] > l) { cnt++; chk[i] = 1; if (i > 1 && chk[i - 1]) { unn(i, i - 1); cnt--; } } } for (int i = 0; i < m; i++) { int mod; scanf("%d", &mod); if (mod) { int t1, t2; scanf("%d%d", &t1, &t2); a[t1] += t2; if (!chk[t1] && a[t1] > l) { cnt++; chk[t1] = 1; if (t1 > 1 && chk[t1 - 1]) { unn(t1, t1 - 1); cnt--; } if (t1 < n && chk[t1 + 1]) { unn(t1, t1 + 1); cnt--; } } } else { printf("%d\n", cnt); } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> using vec = vector<T>; template <typename K, typename V> using umap = unordered_map<K, V>; template <typename K> using uset = unordered_set<K>; using vi = vec<int>; using vl = vec<ll>; using vpi = vec<pii>; using vpl = vec<pll>; using int128 = __int128_t; using uint128 = __uint128_t; template <typename I> string intStr(I x) { string ret; while (x > 0) { ret += (x % 10) + '0'; x /= 10; } reverse(ret.begin(), ret.end()); return ret; } template <typename T> inline void maxa(T& st, T v) { st = max(st, v); } template <typename T> inline void mina(T& st, T v) { st = min(st, v); } inline void setprec(ostream& out, int prec) { out << setprecision(prec) << fixed; } template <typename T> ostream& operator<<(ostream& out, vector<T> iter) { out << "["; for (auto t : iter) { out << t << ", "; } out << "]"; return out; } template <typename T> string arrayStr(T* arr, int sz) { string ret = "["; for (int i = 0; i < sz; i++) { ret += to_string(arr[i]) + ", "; } return ret + "]"; } template <typename T> void printArray(T* arr, int sz) { for (int i = 0; i < sz; i++) { cout << arr[i] << " "; } cout << "\n"; } inline void scan() {} template <typename F, typename... R> inline void scan(F& f, R&... r) { cin >> f; scan(r...); } template <typename F> inline void println(F t) { cout << t << '\n'; } template <typename F, typename... R> inline void println(F f, R... r) { cout << f << " "; println(r...); } inline void print() {} template <typename F, typename... R> inline void print(F f, R... r) { cout << f; print(r...); } template <typename F> inline string __generic_tostring(F f) { stringstream ss; ss << f; return ss.str(); } template <typename F> inline string __join_comma(F f) { return __generic_tostring(f); } template <typename F, typename... R> string __join_comma(F f, R... r) { return __generic_tostring(f) + ", " + __join_comma(r...); } const int MN = 1e5 + 1; int n, q, l, len[MN]; bool over[MN]; set<pii> seg; void append(int x) { auto nxt = seg.upper_bound({x, -1}); if (nxt != seg.end()) { if (x + 1 == nxt->first) { if (nxt != seg.begin()) { auto pre = nxt; pre--; if (pre->second == x - 1) { pii newv = {pre->first, nxt->second}; seg.erase(pre); seg.erase(nxt); seg.insert(newv); return; } } pii newv = {x, nxt->second}; seg.erase(nxt); seg.insert(newv); return; } } if (nxt != seg.begin()) { auto pre = nxt; pre--; if (pre->second == x - 1) { pii newv = {pre->first, x}; seg.erase(pre); seg.insert(newv); return; } } seg.insert({x, x}); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); scan(n, q, l); for (__typeof(1) i = 1; i < n + 1; i++) { scan(len[i]); if (len[i] > l) { append(i); over[i] = true; } } while (q--) { int T; scan(T); if (T == 0) println(seg.size()); else { int idx, v; scan(idx, v); len[idx] += v; if (len[idx] > l && !over[idx]) { append(idx); over[idx] = true; } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 1e5 + 5, mod = 1e9 + 7; int lf[N], re[N]; int main() { ios_base::sync_with_stdio(0), ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, m, l; cin >> n >> m >> l; long long arr[n]; long long pre = -1, numseg = 0, t, p, d; memset(lf, -1, sizeof(lf)); for (int i = 0; i < n; ++i) { cin >> arr[i]; if (arr[i] <= l) pre = -1; else { if (pre == -1) pre = i, lf[i] = i, numseg++; else lf[i] = pre; } } while (m--) { cin >> t; if (!t) cout << numseg << "\n"; else { cin >> p >> d; --p; arr[p] += d; if (arr[p] > l && arr[p] - d <= l) { if (lf[p - 1] == -1 || p == 0) { lf[p] = p; if (lf[p + 1] == -1) numseg++; else lf[p + 1] = p; } else if (lf[p - 1] != -1) { if (p == 0) { if (lf[p + 1] == -1) numseg++, lf[p] = p; else lf[p] = p, lf[p + 1] = lf[p]; } else { if (lf[p + 1] == -1) lf[p] = lf[p - 1]; else lf[p] = lf[p - 1], lf[p + 1] = lf[p], numseg--; } } } } } return 0; }
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> mp; vector<long long int> v1; int main() { long long int n, m, l, i, j, p1, p2, p3; cin >> n >> m >> l; long long int arr[100009]; long long int ans = 0; for (i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] > l) { v1.push_back(i); mp[i] = 1; } } if (v1.size() != 0) { ans = 1; } for (j = 1; j < v1.size(); j++) { if (v1[j] == v1[j - 1] + 1) { continue; } else { ans++; } } for (i = 0; i < m; i++) { cin >> p1; if (p1 == 0) { cout << ans << "\n"; } else { cin >> p2 >> p3; arr[p2] += p3; if (arr[p2] > l) { if (mp[p2] != 1) { int flag1 = 0; int flag2 = 0; if (p2 - 1 > 0) { if (mp[p2 - 1] == 1) { flag1 = 1; } } if (p2 + 1 <= n) { if (mp[p2 + 1] == 1) { flag2 = 1; } } if ((flag1 == 1) && (flag2 == 1)) { if (ans != 0) ans = ans - 1; } else { if ((flag1 == 0) && (flag2 == 0)) { ans++; } } mp[p2] = 1; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int mx = 100005; int n, l, q, a, b; long long int t[mx]; int main() { scanf("%d%d%d", &n, &q, &l); for (int i = 1; i <= n; i++) scanf("%lld", &t[i]); int result = 0; for (int i = 1; i <= n; i++) if (t[i] > l and t[i - 1] <= l) result++; while (q--) { scanf("%d", &a); if (a == 0) { printf("%d\n", result); } else { scanf("%d%d", &a, &b); if (t[a] <= l and t[a] + b > l) { if (t[a - 1] <= l and t[a + 1] <= l) result++; if (t[a - 1] > l and t[a + 1] > l) result--; } t[a] += b; } } }
#include <bits/stdc++.h> using namespace std; const long long md = 1000 * 1000; const int maxi = 200005; vector<pair<long long, long long> > resp; long long tree[400005]; long long n, l; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long q, p, d, k, r, low, hig; long long vet[100005]; pair<long long, long long> range[100005]; cin >> n >> q >> l; for (long long i = 0LL; i < n; i++) { cin >> vet[i]; } r = 0; for (long long i = 0LL; i < n;) { if (vet[i] > l) { r++; k = i; while (k < n && vet[k] > l) k++; i = k; } else { k = i; while (k < n && vet[k] <= l) k++; i = k; } } bool ver = true; while (q--) { cin >> k; if (k) { cin >> p >> d; p--; if (vet[p] <= l && vet[p] + d > l) { if (n == 1) { r = 1; } else { if (!p) { if (vet[p + 1] <= l) r++; } else if (p == n - 1) { if (vet[p - 1] <= l) r++; } else { if (vet[p + 1] <= l && vet[p - 1] <= l) r++; else if (vet[p + 1] > l && vet[p - 1] > l) r--; } } } vet[p] += d; } else { cout << r << endl; } } }
#include <bits/stdc++.h> using namespace std; class UnionFind { int no_c, *c, *s, l; vector<int> *v; public: UnionFind(int n, int l) { no_c = 0, this->l = l; v = new vector<int>[n + 2]; c = new int[n + 2]; s = new int[n + 2]; s[0] = s[n + 1] = 0; for (int i = 1; i <= n; i++) { cin >> s[i]; v[i].push_back(i); c[i] = i; } for (int i = 1; i <= n; i++) { if (s[i] > l) { no_c++; } } for (int i = 1; i <= n; i++) { Union(i - 1, i); Union(i, i + 1); } } void Union(int i, int j) { if (s[i] <= l || s[j] <= l || c[i] == c[j]) { return; } no_c--; int c1 = c[i]; int c2 = c[j]; int n1 = v[c1].size(); int n2 = v[c2].size(); if (n1 <= n2) { for (int i = 0; i < v[c1].size(); i++) { c[v[c1][i]] = c2; v[c2].push_back(v[c1][i]); } v[c1].resize(1); } else { for (int i = 0; i < v[c2].size(); i++) { c[v[c2][i]] = c1; v[c1].push_back(v[c2][i]); } v[c2].resize(1); } } void update(int in, int g) { if (s[in] <= l) { s[in] += g; if (s[in] > l) { no_c++; Union(in, in - 1); Union(in, in + 1); } } } int getAns() { return no_c; } }; int main() { int n, m, l; cin >> n >> m >> l; UnionFind u(n, l); while (m--) { int q; cin >> q; if (!q) { cout << u.getAns() << "\n"; } else { int in, g; cin >> in >> g; u.update(in, g); } } }
#include <bits/stdc++.h> using namespace std; const unsigned _mod = 998244353; const unsigned mod = 1e9 + 7; const long long infi = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; long long ksm(long long x, long long y) { long long ret = 1; while (y) { if (y & 1ll) ret = ret * x % mod; y >>= 1ll; x = x * x % mod; } return ret; } long long qpow(long long x, long long y, long long m) { long long ret = 1; while (y) { if (y & 1ll) ret = ret * x % m; y >>= 1ll; x = x * x % m; } return ret; } long long _gcd(long long x, long long y) { return y ? _gcd(y, x % y) : x; } long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long a[100010], n, m, l, ans, x, p, d; int main() { cin >> n >> m >> l; for (register int i = 1; i <= n; ++i) { a[i] = read(); if (a[i] > l) ans += (a[i - 1] <= l); } for (register int i = 1; i <= m; ++i) { x = read(); if (!x) cout << ans << '\n'; else { p = read(), d = read(); if (a[p] <= l && a[p] + d > l) ans += (1 - (a[p - 1] > l) - (a[p + 1] > l)); a[p] += d; } } return 0; }
#include <bits/stdc++.h> using namespace std; int solve(long long int arr[], long long int p, long long int d, long long int l, int n) { arr[p] += d; if (arr[p] > l && arr[p] - d <= l) { if (p == 0 && arr[p + 1] > l) { return 0; } else if (p == n - 1 && arr[p - 1] > l && p != 0) { return 0; } else if (arr[p + 1] > l && arr[p - 1] > l) { return 2; } else if (arr[p + 1] > l || arr[p - 1] > l && p != 0) { return 0; } else if (arr[p + 1] <= l && arr[p - 1] <= l && p != 0) { return 1; } else { return 1; } } else { return 0; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, m, l, var = 0, ans = 0; cin >> n >> m >> l; long long int arr[n + 1]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } arr[n] = -1; for (int i = 0; i < n; ++i) { if (arr[i] > l) { var = 1; } if (arr[i] <= l) { ans += var; var = 0; } } ans += var; while (m--) { int x; cin >> x; if (x == 0) { cout << ans << '\n'; } else { long long int p, d; cin >> p >> d; int x = solve(arr, p - 1, d, l, n); if (x == 0) { ans += 0; } if (x == 1) { ans += 1; } if (x == 2) { ans += -1; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int SET(int n, int pos) { return n = n | (1 << pos); } int RESET(int n, int pos) { return n = n & ~(1 << pos); } int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); } int str2int(string s) { stringstream ss(s); int x; ss >> x; return x; } string int2str(int a) { stringstream ss; ss << a; string str = ss.str(); return str; } string char2str(char a) { stringstream ss; ss << a; string str = ss.str(); return str; } long long int bigMod(long long int n, long long int power, long long int MOD) { if (power == 0) return 1; if (power % 2 == 0) { long long int ret = bigMod(n, power / 2, MOD); return ((ret % MOD) * (ret % MOD)) % MOD; } else return ((n % MOD) * (bigMod(n, power - 1, MOD) % MOD)) % MOD; } long long int modInverse(long long int a, long long int m) { long long int m0 = m, t, q; long long int x0 = 0, x1 = 1; if (m == 1) return 0; while (a > 1) { q = a / m; t = m; m = a % m, a = t; t = x0; x0 = x1 - q * x0; x1 = t; } if (x1 < 0) x1 += m0; return x1; } int POW(int x, int y) { int res = 1; for (; y;) { if ((y & 1)) { res *= x; } x *= x; y >>= 1; } return res; } int inverse(int x) { double p = ((double)1.0) / x; return (p) + 1e-9; } int gcd(int a, int b) { while (b) b ^= a ^= b ^= a %= b; return a; } int nC2(int n) { return n * (n - 1) / 2; } long long int MOD(long long int n, long long int mod) { if (n >= 0) return n % mod; else if (-n == mod) return 0; else return mod + (n % mod); } long long int data[100005]; int main() { int t, cas = 0; int n, m; long long int l; cin >> n >> m >> l; for (int i = 0; i < n; i++) { scanf("%lld", &data[i]); } int ans = 0; for (int i = 0; i < n; i++) { if (data[i] <= l) continue; for (int j = i; j < n; j++) { if (data[j] <= l) { break; } i = j; } ans++; } while (m--) { int tt; scanf("%d", &tt); if (tt == 0) { printf("%d\n", ans); } else { int p; long long int d; scanf("%d %lld", &p, &d); p--; if (data[p] > l) continue; if (data[p] + d <= l) { data[p] += d; continue; } int x = 0, y = 0; if (p > 0 && data[p - 1] > l) x++; if (p < n - 1 && data[p + 1] > l) y++; if (x && y) ans--; if (!x && !y) ans++; data[p] += d; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long h[100010]; int main() { long long n, m, l; cin >> n >> m >> l; for (int i = 1; i <= n; i++) { cin >> h[i]; } h[0] = 0; long long cnt = 0; for (int i = 1; i <= n; i++) { if (h[i] > l && h[i - 1] <= l) cnt++; } for (int i = 0; i < m; i++) { long long k; cin >> k; if (k) { int x; long long d; cin >> x >> d; if (h[x] + d > l && h[x] <= l) { if (x != 1 && x != n && h[x - 1] > l && h[x + 1] > l) { cnt--; } else if (x == 1) { if (h[x + 1] <= l) cnt++; } else if (x == n) { if (h[x - 1] <= l) cnt++; } else { if (h[x - 1] <= l && h[x + 1] <= l) { cnt++; } } } h[x] += d; } else { cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); int n, m, l; cin >> n >> m >> l; vector<ll> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int answer = 0; for (int i = 0; i < n; ++i) { if (a[i] > l && (i == 0 || a[i - 1] <= l)) { ++answer; } } for (int i = 0; i < m; ++i) { int type; cin >> type; if (type == 0) { cout << answer << "\n"; } else { int p, d; cin >> p >> d; --p; if (a[p] <= l && a[p] + d > l) { ++answer; if (p > 0 && a[p - 1] > l) { --answer; } if (p + 1 < n && a[p + 1] > l) { --answer; } } a[p] += d; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 5; int n, m, l; long long a[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> l; for (auto i = (0); i < (n); i++) cin >> a[i]; int ans = 0; for (auto i = (0); i < (n); i++) { if (a[i] > l && (i == 0 || a[i - 1] <= l)) ++ans; } for (auto i = (0); i < (m); i++) { int tp; cin >> tp; if (!tp) { cout << ans << '\n'; continue; } int j, x; cin >> j >> x; --j; if (a[j] <= l && a[j] + x > l && (j > 0 && j < n - 1 && a[j - 1] > l && a[j + 1] > l)) --ans; if (a[j] <= l && a[j] + x > l && (j == 0 || a[j - 1] <= l) && (j + 1 == n || a[j + 1] <= l)) ++ans; a[j] += x; } return 0; }
#include <bits/stdc++.h> using namespace std; struct hom { int length; int in = 0; }; int main() { int n, m, l; cin >> n >> m >> l; int otr = 0; hom *mas = new hom[n]; for (int i = 0; i < n; i++) { cin >> mas[i].length; if (mas[i].length > l) mas[i].in = 1; } if (mas[0].length > l) otr++; for (int i = 1; i < n; i++) { if (mas[i].length > l && mas[i - 1].in == 0) otr++; } for (int p = 0; p < m; p++) { int qpe; cin >> qpe; if (qpe == 0) cout << otr << endl; else if (qpe == 1) { int nm, dl; cin >> nm >> dl; nm--; mas[nm].length += dl; if (mas[nm].length > l && mas[nm].in == 0) { mas[nm].in = 1; if (nm == 0) { if (mas[1].in == 0) { otr++; continue; } else continue; } if (nm == n - 1) { if (mas[nm - 1].in == 0) { otr++; continue; } else continue; } if (mas[nm - 1].in == 0 && mas[nm + 1].in == 0) otr++; if (mas[nm - 1].in == 1 && mas[nm + 1].in == 1) { otr--; continue; } if (mas[nm - 1].in == 1 || mas[nm = 1].in == 1) continue; } } } }
#include <bits/stdc++.h> using namespace std; long long len[1000006]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, q, t, x, s, m, p, d, l; cin >> n >> m >> l; for (int i = 0; i < n; i++) { cin >> len[i]; } long long co = 0; long long pre; if (n == 1) { if (len[0] > l) co++; for (int i = 0; i < m; i++) { cin >> x; if (x == 1) { cin >> p >> d; pre = len[p - 1]; len[p - 1] += d; if (len[p - 1] > l && pre <= l) { co++; } } else cout << co << "\n"; } return 0; } for (int i = 0; i < n; i++) { if (len[i] > l) { co++; int j = i; while (j < n && len[j] > l) { j++; } if (j > i) i = j; } } long long prev; for (int i = 0; i < m; i++) { cin >> x; if (x == 1) { cin >> p >> d; p--; prev = len[p]; len[p] += d; if (prev <= l) { if (len[p] > l) { if (p == 0) { if (len[p + 1] > l) continue; else { co++; continue; } } else if (p == n - 1) { if (len[p - 1] > l) continue; else co++; } else { if (len[p - 1] > l && len[p + 1] > l) co--; else if (len[p - 1] <= l && len[p + 1] <= l) co++; } } } } else { cout << max(1ll * 0, co) << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e9 + 7; const int N = 5e5 + 500; long long n, m, l, a[N], u[N], cnt; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); cin >> n >> m >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > l) u[i] = 1; } long long f = 0; for (int i = 1; i <= n; i++) { if (u[i] && f == 0) cnt++; f = u[i]; } while (m--) { long long x, y, z; cin >> x; if (x) { cin >> y >> z; a[y] += z; if (a[y] > l && u[y] == 0) { u[y] = 1; if (u[y - 1] && u[y + 1]) cnt--; else if (u[y - 1] == 0 && u[y + 1] == 0) cnt++; } } else { cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; long long n, m, l; long long a[maxn]; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > l && a[i - 1] <= l) ans++; } long long t, p, d; for (int i = 0; i < m; i++) { cin >> t; if (t == 0) { cout << ans << "\n"; } else { cin >> p >> d; a[p] += d; if (a[p] - d <= l && a[p] > l) { ans++; if (a[p - 1] > l) ans--; if (a[p + 1] > l) ans--; } } } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; long long l; cin >> l; vector<long long> arr(n + 5); for (__typeof(n + 1) i = (1) - (1 > n + 1); i != (n + 1) - (1 > n + 1); i += 1 - 2 * (1 > n + 1)) cin >> arr[i]; vector<int> used(n + 2, 0); int grps = 0; for (__typeof(n + 1) i = (1) - (1 > n + 1); i != (n + 1) - (1 > n + 1); i += 1 - 2 * (1 > n + 1)) { if (arr[i] > l) { if (used[i - 1] != 1) grps++; used[i] = 1; } } while (m--) { int t; cin >> t; if (t == 0) cout << grps << '\n'; else { int a, p; cin >> a >> p; arr[a] += p; if (arr[a] > l and used[a] != 1) { used[a] = 1; if (used[a - 1] != 1 and used[a + 1] != 1) grps++; if (used[a - 1] == 1 and used[a + 1] == 1) grps--; } } } return 0; }
#include <bits/stdc++.h> int main() { int n, m, l; std::cin >> n >> m >> l; std::vector<int64_t> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } int ans = (a[0] > l) ? 1 : 0; for (int i = 1; i < n; ++i) { if (a[i] > l && a[i - 1] <= l) { ++ans; } } for (int i = 0; i < m; ++i) { int t; std::cin >> t; if (t == 1) { int64_t p, d; std::cin >> p >> d; --p; if (a[p] + d <= l || a[p] > l) { a[p] += d; } else if (n == 1) { a[p] += d; ans = 1; } else if (p > 0 && p + 1 < n && a[p - 1] <= l && a[p + 1] <= l || p == 0 && a[1] <= l || p + 1 == n && a[p - 1] <= l) { ++ans; a[p] += d; } else if (p > 0 && p + 1 < n && a[p - 1] > l && a[p + 1] > l) { --ans; a[p] += d; } else { a[p] += d; } } else { std::cout << ans << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int mxn = 100005; int lgth[mxn]; bool lng[mxn]; set<pair<int, int> > przed; void dod(int nr) { auto nxt = przed.lower_bound(make_pair(nr, nr)); auto prv = *prev(nxt); int poc = nr, kon = nr; if (nxt->first == nr + 1) { kon = nxt->second; przed.erase(nxt); } if (prv.second == nr - 1) { poc = prv.first; przed.erase(prv); } przed.insert(make_pair(poc, kon)); } int main() { przed.insert(make_pair(-2, -2)); przed.insert(make_pair(mxn, mxn)); int n, m, l; scanf("%d%d%d", &n, &m, &l); for (int i = 0; i < n; i++) { scanf("%d", &lgth[i]); if (lgth[i] > l) { lng[i] = 1; dod(i); } } while (m--) { int t; scanf("%d", &t); if (t == 0) { printf("%d\n", (int)przed.size() - 2); } else { int nr, dl; scanf("%d%d", &nr, &dl); nr--; if (!lng[nr]) { lgth[nr] += dl; if (lgth[nr] > l) { lng[nr] = 1; dod(nr); } } } } }
#include <bits/stdc++.h> using namespace std; signed main() { long long n, m, l, cnt = 0; cin >> n >> m >> l; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } a.push_back(0); for (long long i = 0; i < n; i++) { if (a[i] > l && a[i + 1] <= l) { cnt++; } } while (m--) { long long t; cin >> t; if (t) { long long x, y; cin >> x >> y; x--; a[x] += y; if (a[x] > l && a[x] - y <= l) { if (x != 0 && x != n - 1) { if (a[x - 1] > l && a[x + 1] > l) { cnt--; } else if (a[x - 1] <= l && a[x + 1] <= l) { cnt++; } } else if (!x) { if (a[x + 1] <= l) { cnt++; } } else { if (a[x - 1] <= l) { cnt++; } } } } else { cout << cnt << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, l; cin >> n >> m >> l; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; long long i = 0; while (i < n) { if (a[i] > l) { while (a[i] > l && i < n) { i++; } ans++; continue; } i++; } for (int i = 0; i < m; i++) { long long t; cin >> t; if (t == 1) { long long x, y, z; cin >> x >> y; x--; if (a[x] > l) { a[x] += y; continue; } else if ((a[x] + y) <= l) { a[x] = a[x] + y; continue; } else if (a[x] + y > l) { a[x] += y; if (n == 1) { ans++; continue; } else if (x == 0) { if (a[x + 1] > l) { continue; } else { ans++; continue; } } else if (x == n - 1) { if (a[x - 1] > l) { continue; } else { ans++; continue; } } else { if (a[x - 1] > l && a[x + 1] > l) { ans--; continue; } else if (a[x - 1] > l || a[x + 1] > l) { continue; } else { ans++; continue; } } } } else if (t == 0) { cout << ans << "\n"; } } }
#include <bits/stdc++.h> using namespace std; const int N = int(1e5) + 10; int a[N]; int p[N]; int main() { int n, m, L; cin >> n >> m >> L; set<int> S; for (int i = 0; i < n; i++) { cin >> a[i]; p[i] = i; if (a[i] > L) { S.insert(i); } } for (int i = 1; i < n; i++) { if (a[i] > L && a[i - 1] > L) { if (p[i] != p[i - 1]) { if (S.count(p[i])) { S.erase(S.find(p[i])); } p[i] = p[i - 1]; } } } int cm; int pp, d; for (int i = 0; i < m; i++) { cin >> cm; if (cm == 0) { cout << S.size() << "\n"; } else { cin >> pp >> d; pp--; long long x = a[pp]; x += d; if (x > L) { if (a[pp] <= L) { S.insert(pp); int prev = pp - 1; int next = pp + 1; if (prev >= 0 && a[prev] > L && p[pp] != p[prev]) { if (S.count(p[pp])) { S.erase(S.find(p[pp])); } p[pp] = p[prev]; } if (next < n && a[next] > L && p[pp] != p[next]) { if (S.count(p[next])) { S.erase(S.find(p[next])); } p[next] = p[pp]; } } a[pp] = L + 1; } else { a[pp] += d; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int i, j, k, x, a, b, c, d, n, m, q, t, l, r, ans, temp, T = 1; void solve() { long long a, l, b, c; cin >> n >> m >> l; vector<long long> arr; arr.push_back(0); for (int j = 0; j < n; j++) { cin >> a; arr.push_back(a); } arr.push_back(0); int numC = 0; for (int i = 0; i < n + 2; i++) { if (arr[i] > l) { numC++; while ((i + 1) < (n + 2) && arr[i + 1] > l) i++; } } while (m--) { cin >> a; if (a == 0) { cout << numC; cout << '\n'; } else { cin >> b >> c; if (arr[b] > l) arr[b] += c; else { arr[b] += c; if (arr[b] <= l) continue; else { if ((arr[b - 1] > l) && (arr[b + 1] > l)) numC--; else if ((arr[b - 1] <= l) && (arr[b + 1] <= l)) numC++; } } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[100005], n, q, k; int main() { long long q; scanf("%lld %lld %lld", &n, &q, &k); ; long long cnt = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] > k && a[i - 1] <= k) { cnt++; } } int x, p, r; for (int i = 0; i < q; i++) { scanf("%d", &x); if (!x) { printf("%lld\n", cnt); } else { scanf("%d %d", &p, &r); ; int fl = a[p] > k; a[p] += r; if (fl || a[p] <= k) continue; if (a[p - 1] > k && a[p + 1] > k) cnt--; else if (a[p - 1] > k || a[p + 1] > k) cnt = cnt; else cnt++; } } }
#include <bits/stdc++.h> using namespace std; int t, n, m, l, a[100001], i, check, p, d; bool b[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> l; t = 0; fill(b + 1, b + 1 + n, false); for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > l) { if (i - 1 == 0 || (i - 1 > 0 && b[i - 1] == false)) t++; b[i] = true; } } for (i = 1; i <= m; i++) { cin >> check; if (check == 0) cout << t << '\n'; else { cin >> p >> d; a[p] += d; if (a[p] > l && b[p] == false) { if (p > 1 && p < n) { if (b[p - 1] == true && b[p + 1] == true) { if (t > 1) t--; } else if (b[p - 1] == false && b[p + 1] == false) { if (t < n) t++; } } else if (p == 1) { if (b[p + 1] == false) { if (t < n) t++; } } else if (p == n) { if (b[p - 1] == false) { if (t < n) t++; } } b[p] = true; } } } }
#include <bits/stdc++.h> using namespace std; int n, m, l; int main() { cin >> n >> m >> l; int res = 0; int a[n + 2]; for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); if (a[i] > l) { if (i == 1 || (i > 1 && a[i - 1] <= l)) res++; } } for (int i = 1; i <= m; ++i) { int t, p, d; scanf("%d", &t); if (!t) cout << res << "\n"; else { scanf("%d%d", &d, &p); if (a[d] <= l && a[d] + p > l) { if (d == 1) { if (n == 1) res++; if (n > 1 && a[2] <= l) res++; } else if (d == n) { if ((n > 1 && a[n - 1] <= l)) res++; } else { if (a[d - 1] <= l && a[d + 1] <= l) res++; if (a[d - 1] > l && a[d + 1] > l) res--; } } a[d] = min(a[d] + p, l + 1); } } return 0; }
#include <bits/stdc++.h> using namespace std; long long int nodes[100005] = {0}, par[100005] = {0}; void boost() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { long long int n, m, l; cin >> n >> m >> l; long long int arr[n + 1]; long long int segments = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] > l) { nodes[i] = 1; if ((i - 1) && nodes[i - 1]) { nodes[i - 1]++; nodes[i] = nodes[i - 1]; } else { segments++; } } } while (m--) { long long int q; cin >> q; if (q == 0) { cout << segments << endl; continue; } else { long long int p, d; cin >> p >> d; if (arr[p] > l) { arr[p] += d; } else { arr[p] += d; if (arr[p] > l) { nodes[p] = 1; segments++; if (p - 1 && nodes[p - 1]) { nodes[p] += nodes[p - 1]; nodes[p - 1] = nodes[p]; segments--; } if (p + 1 <= n && nodes[p + 1]) { nodes[p] += nodes[p + 1]; nodes[p + 1] = nodes[p]; segments--; } } } } } }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 7; long long n, m, l; long long a[MAXN]; long long ans = 0; long long get() { return ans; } long long tl[MAXN], tr[MAXN]; void upd(long long p, long long d) { if (a[p] <= l && a[p] + d > l) { if (p && a[p - 1] > l) { --ans; } if (p + 1 < n && a[p + 1] > l) { --ans; } ++ans; } a[p] += d; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> l; for (long long i = 0; i < n; ++i) { long long x; cin >> x; upd(i, x); } for (long long i = 0; i < m; ++i) { long long t; cin >> t; if (t == 0) { cout << get() << '\n'; } else { long long p, d; cin >> p >> d; --p; upd(p, d); } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; using ll = long long; ll a[N]; int n, m, l; int par[N], rnk[N]; void init() { for (int i = 1; i <= n; i++) { par[i] = i; rnk[i] = 0; } } int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) par[x] = y; else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } int main() { scanf("%d%d%d", &n, &m, &l); init(); int cnt = 0, sz = n; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] <= l) cnt++; if (a[i] > l && a[i - 1] > l) { int x = find(i), y = find(i - 1); if (x == y) continue; unite(i, i - 1); sz--; } } while (m--) { int op, p, d; scanf("%d", &op); if (op == 0) printf("%d\n", sz - cnt); else { scanf("%d%d", &p, &d); if (a[p] <= l && a[p] + d > l) { cnt--; int x = find(p), y = find(p - 1), z = find(p + 1); if (a[p - 1] > l && x != y) { unite(x, y); sz--; } if (a[p + 1] > l && x != z) { unite(x, z); sz--; } } a[p] += d; } } }
#include <bits/stdc++.h> using namespace std; template <typename T> void takearray(vector<T> &a, long long int n) { T y; for (long long int i = 0; i < n; i++) { cin >> y; a.push_back(y); } } template <typename T> void print1d(vector<T> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; } void sieveoferatosthenes(long long int n, vector<long long int> &a) { vector<bool> prime(n + 1, true); for (long long int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long int i = p * p; i <= n; i += p) prime[i] = false; } } for (long long int p = 2; p <= n; p++) if (prime[p]) a.push_back(p); } vector<long long int> dectobin(long long int n) { vector<long long int> a; while (n != 0) { a.push_back(n % 2); n = n / 2; } return a; } long long int first_BS(vector<long long int> a, long long int low, long long int high, long long int x) { while (low <= high) { long long int mid = low + (high - low) / 2; if ((mid == 0 || x > a[mid - 1]) && a[mid] == x) return mid; else if (a[mid] < x) low = mid + 1; else high = mid - 1; } return -1; } long long int last_BS(vector<long long int> a, long long int low, long long int high, long long int x) { while (low <= high) { long long int mid = low + (high - low) / 2; if ((mid == a.size() - 1 || x < a[mid + 1]) && a[mid] == x) return mid; else if (x < a[mid]) high = mid - 1; else low = mid + 1; } return -1; } bool sortbool(pair<long long int, long long int> &a, pair<long long int, long long int> &b) { return a.first < b.first; } vector<long long int> numberDivisior(long long int n) { vector<long long int> b; for (long long int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) b.push_back(i); else { b.push_back(n / i); b.push_back(i); } } } return b; } long long int modiBinarySearch(long long int l, long long int r, long long int k) { long long int q, y, mid; while (l <= r) { mid = l + (r - l) / 2; q = (mid * (mid - 1)) / 2; y = (mid * (mid + 1)) / 2; if (q == k) return mid; else if (q < k && y > k) return mid; else if (q > k) r = mid - 1; else l = mid + 1; } return -1; } long double bs(long long int n) { long double l, r; l = 0; r = n; while (l <= r) { long double mid = l + (r - l) / 2; if ((n - mid) * mid == n) return mid; else if ((n - mid) * mid > n) r = mid; else l = mid; } return -1; } unsigned long long int nchoosek(long long int n, long long int r) { unsigned long long int q = 1; if (r == 0 || r == n) return 1; return nchoosek(n - 1, r - 1) + nchoosek(n - 1, r); } bool isPrime(unsigned long long int q) { for (long long int i = 2; i * i <= q; i++) { if (q % i == 0) return false; } return true; } int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long int n, m, l; cin >> n >> m >> l; vector<long long int> a(n, 0); for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int cnt = 0, j = -1; for (long long int i = 0; i < n; i++) { if (a[i] > l) j = 1; else if (a[i] <= l && j == 1) { j = -1; cnt++; } } if (j == 1) cnt++; while (m--) { long long int t; cin >> t; if (t == 1) { long long int p, d; cin >> p >> d; if (a[p - 1] > l) { a[p - 1] += d; continue; } a[p - 1] += d; if (a[p - 1] <= l) continue; if (p != 1 && p != n) { if (a[p] > l && a[p - 2] > l) cnt--; else if (a[p] <= l && a[p - 2] <= l) cnt++; } else if (p == 1 && p == n) { cnt++; } else if (p == 1) { if (a[p] <= l) cnt++; } else if (p == n) { if (a[p - 2] <= l) cnt++; } } else { cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 108011; int t, p, d; int n, m, L; bool vis[maxn]; long long ans[maxn << 2]; int lazy[maxn << 2]; long long a[maxn]; void build(int l, int r, int x) { int i; if (l == r) { ans[x] = a[l]; return; } int m = (l + r) >> 1; build(l, m, x << 1); build(m + 1, r, x << 1 | 1); ans[x] = min(ans[x << 1], ans[x << 1 | 1]); } void update(int l, int r, int x) { int mid = (l + r) >> 1; if (l == p && r == p) { ans[x] += d; return; } if (p <= mid) update(l, mid, x << 1); if (mid < p) update(mid + 1, r, x << 1 | 1); ans[x] = min(ans[x << 1], ans[x << 1 | 1]); } int query(int l, int r, int x) { int Ans = 0; if (ans[x] > L) { return 1; } if (l == r) return 0; int mid = (l + r) >> 1; if ((a[mid] > L) && (a[mid + 1] > L)) Ans -= 1; Ans += query(l, mid, x << 1); Ans += query(mid + 1, r, x << 1 | 1); return Ans; } int main() { cin >> n >> m >> L; int last = 0; int anss = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] > L && last <= L) { anss++; } if (a[i] > L) vis[i] = 1; last = a[i]; } while (m--) { scanf("%d", &t); if (t) { scanf("%d%d", &p, &d); a[p] += d; if (a[p] > L && !vis[p]) { vis[p] = 1; anss++; if (a[p - 1] > L && a[p + 1] > L) anss -= 2; else if (a[p - 1] > L || a[p + 1] > L) anss--; } } else { printf("%d\n", anss); } } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n, m, l; long long a[MAXN]; int ans = 0; int main() { scanf("%d%d%d", &n, &m, &l); for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); } for (int i = 1; i <= n; ++i) { if (a[i] > l) { if (a[i - 1] <= l) ans++; } } int opt, x, y; while (m--) { scanf("%d", &opt); if (!opt) printf("%d\n", ans); else { scanf("%d%d", &x, &y); if (a[x] > l) { a[x] += y; continue; } a[x] += y; if (a[x] > l) { if (a[x - 1] > l && a[x + 1] > l) ans--; if (a[x - 1] <= l && a[x + 1] <= l) ans++; } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const long long INF = 1e9; long long la, ra, ta, lb, rb, tb; struct disjoint_intervals { set<pair<int, int> > s; void insert(pair<int, int> v) { if (v.first >= v.second) return; auto at = s.lower_bound(v); auto it = at; if (at != s.begin() && (--at)->second >= v.first) v.first = at->first, --it; for (; it != s.end() && it->first <= v.second; s.erase(it++)) v.second = max(v.second, it->second); s.insert(v); } }; long long N, M, L; vector<int> hair(MAXN); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> M >> L; disjoint_intervals DI; for (int i = (0); i < int(N); i++) cin >> hair[i]; for (int i = (0); i < int(N); i++) if (hair[i] > L) DI.insert({i, i + 1}); int k, p, d; for (int q = (0); q < int(M); q++) { cin >> k; if (k == 0) cout << DI.s.size() << '\n'; else { cin >> p >> d; hair[p - 1] += d; if (hair[p - 1] > L) DI.insert({p - 1, p}); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, q, l; cin >> n >> q >> l; vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i]; } vector<int> s(n + 1); for (int i = 1; i <= n; ++i) { if (a[i] > l) { s[i] = 1; } } int cnt = 0; for (int i = 1; i <= n; ++i) { if (s[i - 1] == 0 && s[i] == 1) { ++cnt; } } while (q--) { int type; cin >> type; if (type == 0) { cout << cnt << endl; } else { int p, d; cin >> p >> d; if (a[p] > l) { continue; } a[p] += d; if (a[p] > l) { s[p] = 1; } else { continue; } if (a[p] > l && p == n && s[p - 1] == 0) { ++cnt; continue; } if (p == n) { continue; } if (a[p] > l && s[p - 1] == 1 && s[p + 1] == 1) { --cnt; continue; } if (a[p] > l && s[p - 1] == 0 && s[p + 1] == 0) { ++cnt; } } } return 0; }
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; using ll = int64_t; using Pii = pair<int, int>; using ull = uint64_t; using Vi = vector<int>; void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); run(); return 0; } int uplg(int n) { return 32 - __builtin_clz(n); } int uplg(ll n) { return 64 - __builtin_clzll(n); } int cmp(double a, double b, double eps = 1e-9) { return (a > b + eps) - (a + eps < b); } void run() { ll n, m, l; cin >> n >> m >> l; vector<ll> lens(n); for (auto& first : (lens)) cin >> first; ll cur = (lens[0] > l); for (int i = (1); i < (n); i++) if (lens[i] > l && lens[i - 1] <= l) cur++; while (m--) { int t; cin >> t; if (t == 0) { cout << cur << '\n'; } else { int p, d; cin >> p >> d; p--; if (lens[p] > l) continue; lens[p] += d; if (lens[p] <= l) continue; bool left = (p > 0 && lens[p - 1] > l); bool right = (p + 1 < n && lens[p + 1] > l); if (!left && !right) cur++; if (left && right) cur--; } } }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } template <typename T, typename... U> inline void read(T& x, U&... y) { read(x), read(y...); } const int N = 1e5 + 10; int n, Q, K; int sum[N << 2], lx[N << 2], rx[N << 2]; long long A[N << 2]; struct SegmentTree { void Pushup(int o) { sum[o] = sum[o << 1] + sum[o << 1 | 1]; if (rx[o << 1] && lx[o << 1 | 1]) --sum[o]; lx[o] = lx[o << 1]; rx[o] = rx[o << 1 | 1]; } void Build(int l, int r, int o) { if (l == r) { read(A[l]); lx[o] = rx[o] = sum[o] = A[l] > K; return; } int mid = l + r >> 1; Build(l, mid, o << 1); Build(mid + 1, r, o << 1 | 1); Pushup(o); } void Modify(int l, int r, int o, int pos, int d) { if (l == r) { A[l] += d; lx[o] = rx[o] = sum[o] = A[l] > K; return; } int mid = l + r >> 1; if (pos <= mid) Modify(l, mid, o << 1, pos, d); else Modify(mid + 1, r, o << 1 | 1, pos, d); Pushup(o); } } SgT; int main() { read(n, Q, K); SgT.Build(1, n, 1); while (Q--) { int opt, x, y; read(opt); if (!opt) printf("%d\n", sum[1]); else read(x, y), SgT.Modify(1, n, 1, x, y); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m, l; cin >> n >> m >> l; int a[n + 2]; a[0] = -1; a[n + 1] = -1; int ans = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (i == 1 && a[i] > l) { ans += 1; } else if (a[i - 1] <= l && a[i] > l) { ans += 1; } } int t, p, d; for (int i = 0; i < m; ++i) { cin >> t; if (t == 0) { cout << ans << '\n'; } else { cin >> p >> d; if (a[p] > l) { continue; } else if (a[p] + d > l && a[p - 1] <= l && a[p + 1] <= l) { ans += 1; } else if (a[p] + d > l && a[p - 1] > l && a[p + 1] > l) { ans -= 1; } a[p] += d; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, l; long long a[100000 + 10]; int dem = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> l; dem = 0; cin >> a[1]; if (a[1] > l) dem++; for (int i = 2; i <= n; i++) { cin >> a[i]; if (a[i - 1] <= l && a[i] > l) dem++; } int t; for (int i = 1; i <= m; i++) { cin >> t; if (t == 0) cout << dem << '\n'; else { long long p, d; cin >> p >> d; if (a[p] > l) { a[p] += d; continue; }; if (a[p] + d <= l) { a[p] += d; continue; }; a[p] += d; if (n == 1) dem = 1; else if (p == 1 && a[2] <= l) dem++; else if (p == n && a[n - 1] <= l) dem++; else if (p > 1 && p < n && a[p - 1] > l && a[p + 1] > l) dem--; else if (p > 1 && p < n && a[p - 1] <= l && p < n && a[p + 1] <= l) dem++; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, l; cin >> n >> m >> l; long long a[n]; for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i]; int total = 0; for (int(i) = (0); (i) < (n); ++(i)) { if (a[i] > l && (i == 0 || a[i - 1] <= l)) ++total; } while (m--) { int type; cin >> type; if (!type) cout << total << endl; else { int pos, val; cin >> pos >> val; --pos; if (a[pos] <= l && a[pos] + val > l) { if ((pos == 0 || a[pos - 1] <= l) && (pos == n - 1 || a[pos + 1] <= l)) ++total; else if (pos > 0 && pos < n - 1 && a[pos - 1] > l && a[pos + 1] > l) --total; } a[pos] += val; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, l; cin >> n >> m >> l; vector<long long> tmp(n), a(n); for (int i = 0; i < n; i++) { cin >> tmp[i]; } int ans = 0; auto add = [&](int x) { if (x == 0 || a[x - 1] <= l) { ans++; } if (x < n - 1 && a[x + 1] > l) { ans--; } }; for (int i = 0; i < n; i++) { if (tmp[i] > l) { add(i); } a[i] = tmp[i]; } while (m--) { int op; cin >> op; if (op == 0) { cout << ans << '\n'; } else { int x, y; cin >> x >> y; x--; if (a[x] <= l && a[x] + y > l) { add(x); } a[x] += y; } } return 0; }
#include <bits/stdc++.h> long long a[100005]; int b[100005], cnt; void update(int p) { b[p] = 1; cnt++; cnt -= b[p - 1]; cnt -= b[p + 1]; } int main(int argc, char* argv[]) { int i, n, m, t, p; long long d, l; scanf("%d%d%I64d", &n, &m, &l); for (i = 1; i <= n; i++) scanf("%I64d", &a[i]); cnt = 0; memset(b, 0, sizeof b); for (i = 1; i <= n; i++) if (a[i] > l) update(i); while (m--) { scanf("%d", &t); if (t == 0) printf("%d\n", cnt); else { scanf("%d%I64d", &p, &d); if (b[p]) continue; a[p] += d; if (a[p] > l) update(p); } } return 0; }
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int r = 1; x = x % p; while (y) { if (y & 1) r = r * x % p; y = y >> 1; x = x * x % p; } return r; } const int M = 1, N = 1e5 + 9; const int maxn = N; long long int par[maxn], rnk[maxn], a[N]; inline long long int find(int a) { return a == par[a] ? a : par[a] = find(par[a]); } inline void merge(int a, int b) { a = find(a), b = find(b); if (rnk[a] > rnk[b]) swap(a, b); par[a] = b; rnk[b] += rnk[a]; } inline bool same(int a, int b) { return find(a) == find(b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); for (int i = 0; i < maxn; i++) par[i] = i, rnk[i] = 1; long long int n, q, l, ct; cin >> n >> q >> l; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) if (a[i] > l && a[i + 1] > l) merge(i, i + 1); set<long long int> st; for (int i = 0; i < n; i++) if (a[i] > l) st.insert(find(i)); ct = st.size(); while (q--) { int ch; cin >> ch; if (ch == 0) { cout << ct << endl; continue; } long long int i, v; cin >> i >> v; i--; a[i] += v; if (a[i] - v > l || a[i] <= l) continue; if (a[i] - v <= l && a[i] > l) ct++; if (!same(i, i + 1) && i != n - 1 && a[i + 1] > l) { merge(i, i + 1); ct--; } if (!same(i, i - 1) && i != 0 && a[i - 1] > l) { merge(i, i - 1); ct--; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; long long l; cin >> n >> m >> l; vector<long long> hair(n); for (int i = 0; i < n; ++i) { cin >> hair[i]; } int answer = 0; bool isInSegment = false; for (int i = 0; i < n; ++i) { if (isInSegment && hair[i] <= l) { isInSegment = false; ++answer; } else if (!isInSegment && hair[i] > l) { isInSegment = true; } } if (isInSegment) { ++answer; } int type; int p; long long d; for (int j = 0; j < m; ++j) { cin >> type; if (type == 0) { cout << answer << endl; } else { cin >> p >> d; --p; hair[p] += d; if (hair[p] - d > l || hair[p] <= l) { continue; } if (p > 0 && p < n - 1 && hair[p - 1] > l && hair[p + 1] > l) { --answer; continue; } if (p > 0 && hair[p - 1] > l) { continue; } if (p < n - 1 && hair[p + 1] > l) { continue; } ++answer; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int n, q, k, i, j, h = 0, l, m; cin >> n >> q >> k; long long int a[n]; for (i = 0; i < n; ++i) { cin >> a[i]; } l = 0; for (i = 0; i < n; ++i) { if (a[i] > k) { l = 1; } else if (l == 1) { l = 0; h++; } } if (l == 1) h++; while (q--) { cin >> j; if (j == 0) cout << h << endl; else { long long int y = 0; cin >> l >> m; l--; if (n == 1) { a[l] += m; if (a[0] > k) h = 1; } else if (a[l] <= k) { a[l] += m; if (a[l] > k && l > 0 && l < n - 1 && a[l - 1] > k && a[l + 1] > k) h--; else if (a[l] > k && l > 0 && a[l - 1] <= k && l < n - 1 && a[l + 1] <= k) h++; else if (a[l] > k && l == 0 && a[l + 1] > k) h = h; else if (a[l] > k && l == 0 && a[l + 1] <= k) h++; else if (a[l] > k && l == n - 1 && a[l - 1] > k) h = h; else if (a[l] > k && l == n - 1 && a[l - 1] <= k) h++; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, l; cin >> n >> m >> l; int ar[n], q = 0, nq = 0; for (int a = 0; a < n; a++) { scanf("%d", &ar[a]); if (ar[a] > l) q++; } for (int a = 0; a + 1 < n; a++) if (ar[a] > l and ar[a + 1] > l) nq++; for (int a = 0; a < m; a++) { int ty; scanf("%d", &ty); if (ty) { int p, d; scanf("%d%d", &p, &d); p--; if (ar[p] <= l) { ar[p] += d; if (ar[p] > l) { q++; if (p != 0) { if (ar[p - 1] > l) nq++; } if (p + 1 < n) { if (ar[p + 1] > l) nq++; } } ar[p] = min(ar[p], l + 1); } } else printf("%d\n", q - nq); } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1e3; bool vis[MAXN]; long long a[MAXN]; int main() { int n, m, l; scanf("%d%d%d", &n, &m, &l); int ans = 0; for (int i = 1; i <= n; i++) { scanf("%I64d", a + i); if (a[i] > l) { vis[i] = true; if (!vis[i - 1]) ++ans; } } while (m--) { int t; scanf("%d", &t); if (!t) printf("%d\n", ans); else { int p, d; scanf("%d%d", &p, &d); a[p] += d; if (!vis[p] && a[p] > l) { vis[p] = true; if (vis[p - 1] && vis[p + 1]) { ans -= 1; } else if (!vis[p - 1] && !vis[p + 1]) { ans += 1; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\t'; err(++it, args...); } const long double eps = 1e-9; const long long mod = 1e9 + 7; pair<long long, long long> dir[8] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}}; const long long nn = 2e5 + 5; void robin() { long long n, m, l, cnt = 0; cin >> n >> m >> l; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n; i++) { if (a[i] > l) { long long j = i; while (j < n && a[j] > l) j++; i = j; cnt++; } } while (m--) { long long t; cin >> t; if (t == 0) { cout << cnt << "\n"; } else { long long id, d; cin >> id >> d; id--; long long prev = a[id]; a[id] += d; if (prev > l) continue; if (a[id] > l) { if ((id >= 1 && a[id - 1] > l) && (id <= n - 2 && a[id + 1] > l) && prev <= l) { cnt--; continue; } if (id >= 1 && a[id - 1] > l) continue; if (id <= n - 2 && a[id + 1] > l) continue; cnt++; } } } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long T = 1; for (long long tc = 1; tc <= T; tc++) { robin(); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k, ar[1000005], ans[1000005], sum, tut; void f1() { int t, l; cin >> t >> l; if (ar[t] > k) return; ar[t] += l; if (ar[t] > k) { sum++; if (ar[t + 1] > k) sum--; if (ar[t - 1] > k) sum--; } } void f2() { tut++; ans[tut] = sum; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> ar[i]; if (ar[i] > k && ar[i - 1] <= k) sum++; } int a; for (int i = 1; i <= m; i++) { cin >> a; if (a == 0) f2(); else f1(); } printf("\n"); for (int i = 1; i <= tut; i++) cout << ans[i] << "\n"; }
#include <bits/stdc++.h> using namespace std; int n, m, l, o, ans, fa[100005]; long long a[100005]; set<int> S; inline int find_set(int x) { return x == fa[x] ? x : fa[x] = find_set(fa[x]); } int main() { scanf("%d%d%d", &n, &m, &l); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] > l) { fa[i] = i; if (find_set(i - 1)) fa[i] = find_set(i - 1); } } for (int i = 1; i <= n; i++) if (find_set(i)) S.insert(find_set(i)); ans = S.size(); while (m--) { scanf("%d", &o); if (o == 0) printf("%d\n", ans); else { int p, q; scanf("%d%d", &p, &q); a[p] += q; if (a[p] > l && a[p] - q <= l) { fa[p] = p, ans++; if (find_set(p - 1)) fa[p] = find_set(p - 1), ans--; if (find_set(p + 1)) fa[find_set(p)] = find_set(p + 1), ans--; } } } return 0; }
#include <bits/stdc++.h> int n, m, l, t, p, d, a[100005]; int wynik; int main() { scanf("%d%d%d", &n, &m, &l) ?: 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]) ?: 0; if (a[i] > l && a[i - 1] <= l) wynik++; } while (m--) { scanf("%d", &t) ?: 0; if (t == 0) printf("%d\n", wynik); else { scanf("%d%d", &p, &d) ?: 0; if (a[p] <= l && a[p] + d > l) { a[p] = l + 1; wynik++; if (a[p - 1] > l) wynik--; if (a[p + 1] > l) wynik--; } else if (a[p] <= l) a[p] += d; } } }