solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> int mass[100000]; int main() { int res = 0, N, i; scanf("%d", &N); for (i = 0; i < N; i++) scanf("%d", &mass[i]); for (i = N - 1; i >= 1; i--) if (mass[i] < mass[i - 1]) break; printf("%d", i); return 0; }
8
CPP
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int x, temp, c = -1; for (int i = 1; i <= n; i++) { cin >> x; if (i != 1) { if (temp > x) c = i; } temp = x; } if (c == -1) c = 1; cout << c - 1 << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long i, j; long long prime_flag[1000000]; void calculate_prime_flag() { prime_flag[0] = prime_flag[1] = 1; for (i = 2; i < 1000000; i++) { if (prime_flag[i] == 0) { for (j = i * i; j < 1000000; j += i) { prime_flag[j] = 1; } } } } using namespace std; vector<string> v; int LPS(char *str) { int n = strlen(str); int i, j, cl; int l[n][n]; for (i = 0; i < n; i++) l[i][i] = 1; for (cl = 2; cl <= n; cl++) { for (i = 0; i < n - cl + 1; i++) { j = i + cl - 1; if (str[i] == str[j] && cl == 2) l[i][j] = 2; else if (str[i] == str[j]) l[i][j] = l[i + 1][j - 1] + 2; else l[i][j] = max(l[i][j - 1], l[i + 1][j]); } } return l[0][n - 1]; } int main() { ios::sync_with_stdio(false); long long n; cin >> n; long long x; vector<long long> a; for (int i = 1; i <= n; i++) { cin >> x; a.push_back(x); } long long cnt = 1; for (int i = n - 1; i >= 1; i--) { if (a[i] > a[i - 1]) { cnt++; } else break; } cout << n - cnt << endl; return 0; }
8
CPP
#include <bits/stdc++.h> int main(void) { int n; scanf("%d", &n); int i, a[n]; for (i = 0; i <= n - 1; i++) scanf("%d", &(a[i])); i = n - 2; while (a[i + 1] > a[i] && i >= 0) i--; printf("%d", i + 1); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<long long int> v; int a[26]; int main() { long long int n, i, j, k; cin >> n; long long int a[n + 1]; a[0] = INT_MAX; for (i = 1; i <= n; i++) cin >> a[i]; for (i = n; i > 0; i--) { if (a[i] < a[i - 1]) { cout << i - 1; return 0; } } return 0; }
8
CPP
n = int(input()) inStr = input() pos = [int(x) for x in inStr.split()] min = n ans = 0 for i in range(n-1, -1, -1): if pos[i]>min: ans = i+1 break elif pos[i]<min: min = pos[i] print(ans)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, A[100000], k = 0; cin >> n; for (i = 0; i < n; i++) { cin >> A[i]; } for (i = 0; i < n - 1; i++) { if (A[i] > A[i + 1]) k = i + 1; } cout << k; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, idx, ans = 1; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) idx = i; } for (int i = idx; i < n - 1; i++) { if (a[i] > a[i + 1]) ans = 1; else ans++; } cout << n - ans; return 0; }
8
CPP
import os, sys from io import BytesIO, IOBase from types import GeneratorType from bisect import * from collections import defaultdict, deque, Counter import math, string from heapq import * from operator import add from itertools import accumulate BUFSIZE = 8192 sys.setrecursionlimit(10 ** 5) class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: self.os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") inf = float("inf") en = lambda x: list(enumerate(x)) ceil_ = lambda a, b: (a + b - 1) // b ii = lambda: int(input()) r = lambda: map(int, input().split()) rr = lambda: list(r()) # -------------------------- n = ii() arr = rr() c = 0 i = n - 1 while arr[i] > arr[i - 1]: i -= 1 print(i)
8
PYTHON3
n=int(input()) arr=list(map(int,input().split())) temp,count=1000000,0 for i in reversed(arr): if i<temp: temp=i count+=1 if i>temp: break print(n-count)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> V(100001, 0); int N; int main() { int i, p; cin >> N; for (i = 1; i <= N; ++i) { cin >> V[i]; if (V[i] < V[i - 1]) { p = i - 1; } } cout << p; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int DP[100005]; int n; int main() { fill(DP, DP + 100005, 0); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &DP[i]); } int ans = 0, k = n + 1; for (int i = n - 1; i != -1; i--) { if (k > DP[i]) { k = DP[i]; ans++; } else break; } printf("%d\n", n - ans); }
8
CPP
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); int ar[t + 2]; int i; int nt = 0; for (i = 0; i < t; i++) scanf("%d", &ar[i]); int j = 0; int no = 0; while (j < t - 1) { if (ar[j] < ar[j + 1]) { no++; j++; } else { nt++; nt += no; no = 0; j++; } } printf("%d\n", nt); return 0; }
8
CPP
#include <bits/stdc++.h> int f[100009]; int main() { int n; while (scanf("%d", &n) != EOF) { int i; int l = 1; int sum = 1; for (i = 0; i < n; i++) { scanf("%d", &f[i]); } for (i = n - 2; i >= 0; i--) { if (f[i] < f[i + 1]) sum++; else break; } printf("%d\n", n - sum); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; string str; stringstream ss; getline(cin, str); ss << str; ss >> n; ss.clear(); getline(cin, str); ss << str; int i = 0; while (ss >> a[i]) i++; for (int i = n - 1; i > 0; i--) { if (a[i - 1] > a[i]) { cout << i << endl; return 0; } } cout << 0 << endl; }
8
CPP
import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up downa """ n, = I() a = I() i = n - 1 while i > 0 and a[i - 1] < a[i]: i -= 1 print(i)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long ll, i, j, k, l, m, s, t, n, x, y, cl, ss, ce, a[623456], b[212345], c[212356], d[1234]; string p, q, rr; vector<string> w[2123]; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } if (n == 1) { cout << 0; return 0; } for (i = 0; i < n - 1; i++) { if (a[i + 1] < a[i]) { t = 1; s = i; } } if (t == 1) cout << s + 1; else cout << s; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, ar[200000], f[200000]; int main() { vector<int> ans; cin >> n; memset(f, 0, n); for (int i = 1; i <= n; i++) cin >> ar[i]; int i = n; while (i > 1 && ar[i - 1] < ar[i]) { i--; } cout << i - 1 << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int n, m, i, j, k, l, c = 0, v = 0, u = 0, a[1000001]; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = n; i >= 1; i--) { c++; if (a[i] < a[i - 1]) { v++; printf("%d", n - c); break; } } if (v == 0) printf("0"); return 0; }
8
CPP
import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) for i in range(n-2, -1, -1): if a[i+1] < a[i]: print(i+1) break else: print(0)
8
PYTHON3
#include <bits/stdc++.h> long _abs(long a) { if (a < 0) return -a; else return a; } using namespace std; int main() { long n, x; cin >> n; int a[111111]; int ans = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) if (a[i] > a[i + 1]) ans = i + 1; cout << ans; }
8
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int MAX = 1e5 + 5; const long long MAX2 = 11; const long long MOD = 998244353; const long long MOD2 = 1000005329; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0}; const double pi = acos(-1); const double EPS = 1e-9; const int block = 2000; int n, x[MAX], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> x[i]; for (int i = n - 1; i >= 1; --i) if (x[i] > x[i + 1]) { ans = i; break; } cout << ans << '\n'; return 0; }
8
CPP
# Exercicio H n = int(input()) t = input().split() thread = [] for i in range(n): thread.append(int(t[i])) position = 0 for j in range(n-1): if thread[j] > thread[j + 1]: position = j + 1 print(position)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 100050; int a[maxn]; int main() { int i, j, n, flag, ci = 0; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i - 1] > a[i]) ci = i - 1; } printf("%d\n", ci); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int i; int n = 0; cin >> n; int *a; a = new int[n]; for (i = 0; i < n; i++) { cin >> a[i]; } int lenght = 1; for (i = n - 2; a[i] < a[i + 1] && i != -1; i--) { lenght++; } cout << n - lenght << endl; delete a; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, m, t; bool l; vector<int> v; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> m, v.push_back(m); for (int i = n - 1; i > 0; i--) { if (v[i] < v[i - 1]) { cout << i; return 0; } } cout << 0; return 0; }
8
CPP
n = int(input()) a = list(map(int, input().split())) no = n - 1 minm = a[-1] for i in range(n - 2, -1, -1): if a[i] <= minm: no -= 1 minm = a[i] else: break print(no)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, a0, ascending(1); cin >> n >> a0; for (int i = 1; i < n; i++) { cin >> a; if (a > a0) { ascending += 1; } else { ascending = 1; } a0 = a; } cout << n - ascending << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = n - 2; i >= 0; i--) if (arr[i] > arr[i + 1]) { cout << i + 1; return 0; } cout << 0; return 0; }
8
CPP
n=int(input()) temp=0 c=0 a=input().split() for i in range(0,n): if(temp-int(a[i])>0): c=i+1 temp=int(a[i]) if(c!=0): print (c-1) else: print(0)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n, k = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int m = n + 1, mm = -1; for (int i = n - 1; 0 <= i; i--) { if ((a[i] > m) || (a[i] < mm)) { k++; if (a[i] > mm) mm = a[i]; } if (a[i] < m) m = a[i]; } cout << k; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, mn[100005]; int main() { int ans = 0, ind = 1; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &mn[i]); } for (int i = n - 1; i >= 1; --i) if (mn[i] > mn[i + 1]) { printf("%d", i); return 0; } printf("0"); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back(x); } int cnt = 0; int max = 0; for (int i = 0; i < n; i++) { if (max <= a[i]) { max = a[i]; cnt++; } else { max = a[i]; cnt = 1; } } cout << n - cnt << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; a.reserve(n + 1); vector<int> ind(n + 1); for (long long i = 0; i < n; ++i) { int tmp; cin >> tmp; a.push_back(tmp); ind[tmp] = i; } int offset = 0; for (int i = n; i >= 1; i--) { if (ind[i] < a[ind[i]] - 1 + offset) offset++; } cout << offset << endl; return 0; }
8
CPP
n=int(input()) l=list(map(int,input().split())) x=0 for i in range(n-1,-1,-1): if(l[i]<l[i-1]): x=i break print(x)
8
PYTHON3
t=int(input()) arr=list(map(int,input().split())) i=t-1 while( i>0 and arr[i] > arr[i-1] ): i-=1 print(i)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[100005]; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int m = n - 1; while (m) { if (a[m] > a[m - 1]) m--; else break; } printf("%d\n", m); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long int n, m, i; int k = 0, j; scanf("%ld", &n); long int a[n]; for (i = 0; i < n; i++) scanf("%ld", &a[i]); for (i = n - 1; i > 0; i--) { if (a[i - 1] > a[i]) { k = i; break; } } printf("%d\n", k); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, a[100001], res = 1; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int i = n; while (a[i - 1] < a[i] && i > 1) res++, i--; cout << n - res; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; while (cin >> n) { for (int i = 0; i < n; i++) cin >> a[i]; int ct = 0; for (int i = n - 1; i >= 1; i--) if (a[i - 1] > a[i]) break; else ct++; cout << n - ct - 1 << endl; } }
8
CPP
n=int(input("")) a=[int(x) for x in input("").split(' ')] output = 0 cache = 0 for x in range(n-1): if a[x] > a[x+1]: output+=1+cache cache=0 else: cache+=1 print(output)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int inf = 1e18; const long long int N = 200001; int main() { long long int n; cin >> n; long long int arr[n]; for (long long int i = 0; i < n; i++) { cin >> arr[i]; } long long int pos[n]; pos[0] = 0; for (long long int i = 1; i < n; i++) { if (arr[i] > arr[i - 1]) { pos[i] = pos[i - 1]; } else { pos[i] = i; } } cout << pos[n - 1]; return 0; }
8
CPP
n = int(input()) threads = [int(i) for i in input().split()] min = threads[n - 1] new = 0 for i in range(2, n + 1): if threads[n - i] > min: new = n - i + 1 break else: min = threads[n - i] print(new)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int t, n, m, x = 0, y = 0, flag = 0, cnt = 0, sum = 0, sum1 = 0, sum0 = 0, flag1 = 0; int a1, a2, a3, b1, b2, b3; vector<int> d; cin >> t; int a[t]; for (int i = 0; i < t; i++) { cin >> a[i]; } x = t - 1; while (x > 0 && a[x - 1] < a[x]) { x--; } cout << x << "\n"; return 0; }
8
CPP
import re, sys, string, operator, functools, fractions, collections from random import * sys.setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() mod=1e9+7 eps=1e-6 ################################################# n=RI()[0] a=RI() ans=1 for i in range(n-1,0,-1): if a[i-1]>a[i]: break ans+=1 print(n-ans)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, i; int a[100010]; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = n; i >= 1; i--) if (a[i] < a[i - 1]) break; if (i == 0) cout << "0"; else cout << i - 1; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } if (n == 1) { cout << 0 << '\n'; return 0; } int k = a.size() - 1; for (int i = a.size() - 2; i >= 0; --i) { if (a[i] > a[i + 1]) { break; } k = i; } cout << a.size() - (a.size() - k) << '\n'; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> v, u; pair<long long, long long> n; set<string> y; long long a, b, c, d = 0, e = 1, i, f = 0, g = 0, j, k = 0, l = 0, r = 0, z, m, h, p[100001]; string t, s, x, q; double w; cin >> a; for (i = 1; i <= a; i++) { cin >> p[i]; } while (a > 1 && p[a - 1] < p[a]) { a--; } cout << a - 1; }
8
CPP
#include <bits/stdc++.h> int a[100050]; int main() { if (0) { freopen("b2.txt", "r", stdin); }; int n; scanf("%d", &n); for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]); int i = n; while (i > 1 && a[i] > a[i - 1]) i--; printf("%d\n", i - 1); return 0; }
8
CPP
nr_threads = int(input()) old_position = list(map(int,input().split())) ans = nr_threads-1 if(nr_threads == 1): print(0) quit() i = ans while (i > 0): if (old_position[i-1] > old_position[i]): print(ans) quit() else: i -=1 ans -=1 print(ans)
8
PYTHON3
#include <bits/stdc++.h> int a[100005] = {0}; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int ans = 0; for (int j = n - 1; j >= 1; j--) if (a[j] > a[j + 1]) { ans = j; break; } printf("%d\n", ans); return 0; }
8
CPP
#include <bits/stdc++.h> int nums_[100001]; int main() { int n, i; scanf("%d\n", &n); for (i = 1; i <= n; ++i) { scanf("%d", &nums_[i]); } i = n - 1; for (; i >= 1 && nums_[i] < nums_[i + 1]; --i) ; printf("\n%d\n", i); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, a, ans = 0, temp = 0; cin >> n; for (long long i = (long long)(1); i <= (long long)(n); i++) { cin >> a; if (temp > a) { ans = i - 1; } temp = a; } cout << ans; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[100009]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = n - 2; i >= 0; i--) { if (a[i] > a[i + 1]) { cout << i + 1; return 0; } } cout << 0; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int array[n]; for (int i = 0; i < n; i++) cin >> array[i]; int count = n - 1; for (int i = n - 2; array[i] < array[i + 1]; i--) { count--; } cout << count; }
8
CPP
#include <bits/stdc++.h> int main() { int n, i, a[100001]; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = n; i >= 2; i--) if (a[i] < a[i - 1]) break; printf("%d\n", i - 1); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a = 0, b, maxi = -1; for (int(i) = 0; (i) < (n); (i)++) { cin >> b; if (b < a) maxi = i - 1; a = b; } cout << maxi + 1; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926536; int const N = 1000005; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; for (int i = n - 1; i >= 1; i--) { if (a[i] < a[i - 1]) { ans = i; break; } } cout << ans; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, o, f = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } o = n - 1; for (int i = n - 1; i >= 0; i--) { if (a[i] > a[i - 1]) { o--; } else { cout << o << endl; return 0; } } }
8
CPP
#include <bits/stdc++.h> using namespace std; int order[100005]; int main() { int i, j, k, n; while (~scanf("%d", &n)) { for (i = 0; i < n; i++) scanf("%d", &order[i]); for (i = n - 1; i >= 1 && order[i] > order[i - 1]; i--) ; printf("%d\n", i); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7, mod = 1000000007; long long int a[N], cnt, sum, mx; vector<pair<pair<long long int, long long int>, long long int>> v; priority_queue<long long int, vector<long long int>, greater<long long int>> pq; long long int kk; stack<char> st; long long int vis[N]; map<pair<long long int, long long int>, vector<pair<long long int, long long int>>> mp; map<pair<long long int, long long int>, long long int> pm; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int z = 0, n, m = 0, mn = 0, mx = 0, i = 0, x = 0, y = 0, k, j = 0, xx, yy; string s, r; char c; pair<long long int, long long int> p1, p2; p1 = p2 = {0, 0}; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = n - 1; i >= 0; i--) { if (i == 0) break; if (a[i] < a[i - 1]) break; } cout << i; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int i = n - 1; while (i > 0 && a[i - 1] < a[i]) --i; cout << i << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> tree; void build(vector<long long> &arr, long long ind, long long l, long long r) { if (l == r) { tree[ind] = arr[l]; return; } long long mid = (l + r) / 2; build(arr, ind * 2, l, mid); build(arr, ind * 2 + 1, mid + 1, r); tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]); } long long getMax(long long ind, long long tl, long long tr, long long l, long long r) { if (l > r) return 0; if (l == tl && r == tr) return tree[ind]; long long tm = (tl + tr) / 2; long long a = getMax(ind * 2, tl, tm, l, min(r, tm)); long long b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r); return max(a, b); } int main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long count = 1; for (int i = n - 2; i >= 0; i--) { if (a[i] < a[i + 1]) { count++; } else { break; } } cout << n - count; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0; cin >> n; int a[n]; cin >> a[0]; for (int i = 1; i < n; i++) { cin >> a[i]; if (a[i] < a[i - 1]) x = i; } cout << x; return 0; }
8
CPP
n = int(input()) a = [int(x) for x in input().split()] answer = 0 last = a[-1] for v in reversed(a): if v > last: break answer += 1 last = v print(len(a) - answer)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long int t, n, m, q, l, r; long int arr[100001]; int main() { long int i, j, k, a, b, c, ans; scanf("%ld", &n); a = ans = 0; for (i = 1; i <= n; i++) { scanf("%ld", &arr[i]); } for (i = n - 1; i > 0; i--) { if (arr[i] > arr[i + 1]) { ans = i; break; } } cout << ans; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int ar[100009], n, res; int main() { while (scanf("%d", &n) != EOF) { for (int i = 0, _n = n; i < _n; i++) { scanf("%d", &ar[i]); } res = 0; for (int i = n - 2; i >= 0; i--) { if (ar[i] > ar[i + 1]) { res = i + 1; break; } } printf("%d\n", res); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n; int arr[100100]; int cal() { for (int i = n; i > 1; i--) { if (arr[i] < arr[i - 1]) return i - 1; } return 0; } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; } cout << cal() << endl; return 0; }
8
CPP
#include <bits/stdc++.h> int main() { int i, j, a[100000], n, count = 0; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = n - 1, j = n - 2; j >= 0; j--, i--) if (a[j] < a[i]) count++; else break; if (count == 0) printf("%d", n - 1); else printf("%d", n - count - 1); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int INF = 100000; const int MAXN = 100000; int a[MAXN]; int n; int ans; int main() { cin >> n; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) cin >> a[i]; ans = 0; int k = 0; bool f = false; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { if (!f) { ans = 0; k = i; f = true; } ans++; continue; } f = false; } ans += k; cout << ans << endl; return 0; }
8
CPP
#include <bits/stdc++.h> int main() { int a[100010]; int n; scanf("%d", &n); int sure = 1; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = n - 2; i >= 0; --i) { if (a[i] < a[i + 1]) { ++sure; } else { break; } } printf("%d\n", n - sure); }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, a[100000], b[100000], c; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); b[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) b[i] = min(a[i], b[i + 1]); for (int i = 0; i < n - 1; i++) if (a[i] > b[i + 1]) c = i + 1; printf("%d\n", c); return 0; }
8
CPP
#include <bits/stdc++.h> const int MAXN = 100000; int a[MAXN]; int main() { int N; int i, pre, now, ans; scanf("%d", &N); ans = pre = 0; for (i = 0; i < N; ++i) { scanf("%d", &now); if (pre > now) ans = i; pre = now; } printf("%d", ans); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dx1[] = {-1, 0, 0, 1}; int dy1[] = {0, -1, 1, 0}; vector<vector<int> > adj; vector<bool> visited; void dfs(int v) { visited[v] = true; for (int u : adj[v]) { if (!visited[u]) dfs(u); } } long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } bool isprime(long long n) { if (n == 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i += 6) { if ((n % i == 0) || (n % (i + 2) == 0)) return false; } return true; } long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } long long ncr(long long x, long long y) { long long ans = 1; for (long long i = 1; i <= y; ++i) { ans *= (x - y + i); ans /= i; } return ans; } long long phi(long long n) { long long result = n; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n /= i; result -= result / i; } } if (n > 1) result -= result / n; return result; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; vector<int> v1; int a1; for (int i = 0; i < n; ++i) { cin >> a1; v1.push_back(a1); } int ans = n - 1; for (int i = n - 1; i >= 0; i--) { if (v1[i] > v1[i - 1]) ans--; else break; } cout << ans << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long c = 1, ans = 0; long long n; cin >> n; long long a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = n - 1; i >= 1; --i) { if (a[i - 1] > a[i]) { cout << i; return 0; } } cout << 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, i, k, l, q, j, a[100005], max1; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n - 1; i++) if (a[i + 1] < a[i]) { max1 = i + 1; } printf("%d\n", max1); }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n + 1]; int track = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i < n; i++) if (arr[i] > arr[i + 1]) track = i; cout << track << endl; return 0; }
8
CPP
#include <bits/stdc++.h> int main() { int n, i; int a[100005]; while (scanf("%d", &n) == 1) { for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = n - 1; i > 0; i--) { if (a[i] < a[i - 1]) { break; } } printf("%d\n", i); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int count = 0; for (int i = 1; i < n; i++) { if (a[i - 1] > a[i]) { count = i; } } cout << count << endl; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long int a, c[1000001], d, e = 0, f, i, j, l, max1 = -999999999; int main() { cin >> a; for (i = 0; i < a; i++) { cin >> c[i]; } for (i = a - 1; i > 0; i--) { if (c[i] > c[i - 1]) e++; else break; } e++; cout << a - e << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n, res = 0; cin >> n; long long niz[n]; for (int i = 0; i < n; i++) cin >> niz[i]; for (int i = n - 1; i >= 1; i--) { if (niz[i] > niz[i - 1]) { res++; } else break; } cout << n - res - 1; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = int(1e5); int n, ans = 0; int a[N]; int main(int argc, char *argv[]) { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = n - 1; i; --i) { if (a[i] < a[i - 1]) { printf("%d", i); return 0; } } printf("0"); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long kiran_bhanushali[29][7][20]; void init() { for (long long i = 0; i < 29; i++) { kiran_bhanushali[i][0][0] = rand() % 1000; } } void solve() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; long long i = n - 1; while (i >= 0 && a[i - 1] < a[i]) { i--; } cout << i << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; init(); long long t = 1; while (t--) { solve(); } return 0; }
8
CPP
n = int(input()) a = list(map(int, input().split()))[::-1] c = 0 for i in range(1, n): if a[i] > a[i-1]: c = n-i break print(c)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long n, i; cin >> n; long long a[n], c = 0; for (long long i = 0; i < n; i++) cin >> a[i]; for (i = n - 1; i >= 1; i--) if (a[i - 1] > a[i]) break; cout << i; }
8
CPP
input() t=[int(x) for x in input().split()] m=[True]+[t[i]>t[i+1] for i in range(len(t)-1)] print(len(m)-1-list(reversed(m)).index(True))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int xChange[] = {0, 1, 0, -1}; int yChange[] = {1, 0, -1, 0}; const int N = (int)1e5 + 5; int a[N], n, ans; int main() { ios::sync_with_stdio(false), cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int idx = 0; for (int i = n - 1; i >= 0; i--) { idx = i; if (a[i] < a[i - 1]) break; } cout << idx; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int A[100000], N, i; cin >> N; for (i = 0; i < N; ++i) cin >> A[i]; for (i = N - 2; i >= 0 && A[i] < A[i + 1]; --i) ; cout << i + 1; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n; int a[100005]; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); int flag = -1; for (i = 0; i < n - 1; i++) if (a[i] > a[i + 1]) flag = i; printf("%d\n", flag + 1); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, ans; int arr[100005]; int main() { int i; while (scanf("%d", &n) != EOF) { ans = 0; for (i = 0; i < n; i++) scanf("%d", arr + i); for (i = n - 2; i >= 0; i--) { if (arr[i + 1] > arr[i]) { ans++; continue; } else break; } printf("%d\n", n - ans - 1); } return 0; }
8
CPP
n=int(input()) a=list(map(int,input().split())) ans=n-1 for i in range(n-1,0,-1): if(a[i-1]>a[i]): break ans-=1 print(ans)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a[100001], c = 0; scanf("%d", &n); for (i = 0; i < (n); ++i) scanf("%d", &a[i]); for (i = n - 2; i >= 0; --i) if (a[i] > a[i + 1]) { c = i + 1; break; } cout << c << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point() {} Point(int x, int y) { this->x = x; this->y = y; } Point operator+(Point rhs) { return Point(x + rhs.x, y + rhs.y); } Point operator-(Point rhs) { return Point(x - rhs.x, y - rhs.y); } long long Dot(Point rhs) { return 1LL * x * rhs.x + 1LL * y * rhs.y; } long long Crs(Point rhs) { return 1LL * x * rhs.y - 1LL * y * rhs.x; } }; bool operator<(Point lhs, Point rhs) { return (lhs.x == rhs.x) ? (lhs.y < rhs.y) : (lhs.x < rhs.x); } const int MAXN = 100010; int N; Point p[MAXN]; vector<Point> H[2]; int pcx[2333333], pcy[2333333]; int *cx = pcx + 1233333, *cy = pcy + 1233333; long long cip; double Stat(int* e, int Min, int Max) { double ret = 0; double Count = 0, sumPlain = 0, sumSquare = 0; int i; for (i = Min; i <= Max; i++) { ret += e[i] * (Count * i * i + sumSquare - 2.0 * i * sumPlain); Count += e[i]; sumPlain += e[i] * 1.0 * i; sumSquare += e[i] * 1.0 * i * i; } return ret; } int main() { scanf("%d", &N); int i; for (i = 1; i <= N; i++) { int x, y; scanf("%d%d", &x, &y); p[i] = Point(x, y); } sort(p + 1, p + N + 1); int ml = 1; while ((ml < N) && (p[ml + 1].x == p[1].x)) ml++; H[0].clear(); H[1].clear(); H[0].push_back(p[1]); H[1].push_back(p[ml]); for (i = ml + 1; i <= N; i++) { while ((H[0].size() > 1) && ((H[0].back() - H[0][H[0].size() - 2]).Crs(p[i] - H[0].back()) <= 0)) H[0].pop_back(); while ((H[1].size() > 1) && ((H[1].back() - H[1][H[1].size() - 2]).Crs(p[i] - H[1].back()) >= 0)) H[1].pop_back(); H[0].push_back(p[i]); H[1].push_back(p[i]); } while ((H[0].size() > 1) && (H[0].back().x == H[0][H[0].size() - 2].x)) H[0].pop_back(); vector<Point>::iterator lit = H[0].begin(), rit = H[1].begin(); int minX = p[1].x, maxX = p[N].x, minY = p[1].y, maxY = p[1].y; for (i = 2; i <= N; i++) { minY = min(minY, p[i].y); maxY = max(maxY, p[i].y); } for (i = minY; i <= maxY; i++) cy[i] = 0; cx[maxX] = H[1].back().y - H[0].back().y + 1; cy[H[1].back().y + 1]--; cy[H[0].back().y]++; for (i = minX; i <= maxX - 1; i++) { if ((lit + 1)->x <= i) lit++; if ((rit + 1)->x <= i) rit++; int ly = ceil(double((lit + 1)->y - lit->y) / ((lit + 1)->x - lit->x) * (i - lit->x) + lit->y - 1e-9); int ry = floor(double((rit + 1)->y - rit->y) / ((rit + 1)->x - rit->x) * (i - rit->x) + rit->y + 1e-9); cx[i] = ry - ly + 1; cy[ry + 1]--; cy[ly]++; } for (i = minY + 1; i <= maxY; i++) cy[i] += cy[i - 1]; cip = 0; for (i = minX; i <= maxX; i++) cip += cx[i]; double ans = Stat(cx, minX, maxX) + Stat(cy, minY, maxY); ans /= cip; ans /= cip - 1; printf("%.10f\n", ans); }
10
CPP
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < '0' || C > '9';) if (C == '-') F = 1; for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0') ; F && (T = -T); } pair<int, int> A[1000005]; int N; void Init() { Get(N); for (int i = 1; i <= N; i++) { Get(A[i].first); Get(A[i].second); A[i].first += 1000005; A[i].second += 1000005; } } double Floor(int X, int Y, int P) { double Y1 = A[X].second + (double)(P - A[X].first) * (A[Y].second - A[X].second) / (double)(A[Y].first - A[X].first); return floor(Y1 + (1e-8)); } double Ceil(int X, int Y, int P) { double Y1 = A[X].second + (double)(P - A[X].first) * (A[Y].second - A[X].second) / (double)(A[Y].first - A[X].first); return ceil(Y1 - (1e-8)); } long double F[10000005]; long double Ans; void Calc() { rotate(A + 1, min_element(A + 1, A + N + 1), A + N + 1); A[N + 1] = A[1]; int Pos = max_element(A + 1, A + N + 1) - A; int P = A[1].first, Q = A[Pos].first; for (int i = P, k = 1; i <= Q; i++) { for (; A[k + 1].first < i;) k++; int Pos = Ceil(k, k + 1, i); F[i] = -Pos + 1; } long double Cnt = 0; long double SumX = 0; for (int i = Q, k = Pos; i >= P; i--) { for (; A[k + 1].first > i;) k++; int Pos = Floor(k, k + 1, i); F[i] += Pos; Cnt += F[i]; SumX += (i - 1000005) * F[i]; } for (int i = Q; i >= P; i--) Ans += F[i] * (i - 1000005) * (i - 1000005) / (Cnt - 1); Ans -= SumX * SumX / ((Cnt - 1) * Cnt); } void Work() { double S = 0; A[N + 1] = A[1]; for (int k = 1; k <= N + 1; k++) S += (double)A[k].first * (double)A[k + 1].second - (double)A[k].second * (double)A[k + 1].first; if (S < 0) reverse(A + 1, A + N + 1); Calc(); for (int k = 1; k <= N; k++) std::swap(A[k].first, A[k].second); reverse(A + 1, A + N + 1); Calc(); } void Output() { printf("%.15lf\n", (double)Ans); } int main() { Init(); Work(); Output(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } template <typename T1, typename T2> inline T1 gmax(T1 &a, T2 b) { return a = a < b ? b : a; } template <typename T1, typename T2> inline T1 gmin(T1 &a, T2 b) { return a = a < b ? a : b; } const char lf = '\n'; namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t = buf; inline int fetch() { if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; } return *s++; } inline int ty() { int a = 0; int b = 1, c = fetch(); while (!isdigit(c)) b ^= c == '-', c = fetch(); while (isdigit(c)) a = a * 10 + c - 48, c = fetch(); return b ? a : -a; } } // namespace ae86 using ae86::ty; const int _ = 100007, X = 1000000, inf = 0x3f3f3f3f; struct points { long long x, y; points(long long x_ = 0, long long y_ = 0) { x = x_, y = y_; } void takein() { x = ty(), y = ty(); } void rever() { swap(x, y); } friend points operator+(points a, points b) { return points(a.x + b.x, a.y + b.y); } friend points operator-(points a, points b) { return points(a.x - b.x, a.y - b.y); } }; inline long long dox(points a, points b) { return a.x * b.x + a.y * b.y; } inline long long cox(points a, points b) { return a.x * b.y - a.y * b.x; } inline long long length2(points a) { return dox(a, a); } inline long long distan2(points a, points b) { return length2(b - a); } int n; points p[_]; int xlBuf[X + X + 7], xrBuf[X + X + 7], *xl = xlBuf + X + 3, *xr = xrBuf + X + 3; double make() { for (int i = -X; i <= X; i++) xl[i] = inf, xr[i] = -inf; for (int i = 1; i <= n; i++) { if (p[i].x == p[i + 1].x) gmin(xl[p[i].x], p[i].y), gmax(xr[p[i].x], p[i].y); else { points a = p[i], b = p[i + 1]; if (a.x > b.x) swap(a, b); double k = 1.00 / (b.x - a.x); for (int j = a.x; j <= b.x; j++) { double loc = ((j - a.x) * b.y + (b.x - j) * a.y) * k; gmin(xl[j], ceil(loc)), gmax(xr[j], floor(loc)); } } } double s = 0, si = 0, si2 = 0; for (int i = -X; i <= X; i++) { if (xr[i] < xl[i]) continue; long long dlt = xr[i] - xl[i] + 1; s += dlt, si += dlt * i, si2 += dlt * i * i; } return (s * si2 - si * si) / s / (s - 1); } int main() { ios::sync_with_stdio(0), cout.tie(nullptr); n = ty(); for (int i = 1; i <= n; i++) p[i].takein(); p[0] = p[n], p[n + 1] = p[1]; double ans = make(); for (int i = 0; i <= n + 1; i++) p[i].rever(); ans += make(); cout << setprecision(11) << fixed << ans << lf; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n; struct data { int x, y; } d[maxn]; double U[2000005], D[2000005], ans; void Max(double &x, double y) { if (x < y) x = y; } void Min(double &x, double y) { if (x > y) x = y; } void work() { int i, j, mx = 0; d[n] = d[0]; for (i = 0; i < n; i++) if (mx < d[i].x) mx = d[i].x; for (i = 0; i <= mx; i++) D[i] = 2000005., U[i] = -1.; for (i = 0; i < n; i++) { if (d[i].x == d[i + 1].x) { Max(U[d[i].x], d[i].y); Max(U[d[i].x], d[i + 1].y); Min(D[d[i].x], d[i].y); Min(D[d[i].x], d[i + 1].y); } else { int l, r; double k = 1. * (d[i + 1].y - d[i].y) / (d[i + 1].x - d[i].x), b; if (d[i].x < d[i + 1].x) l = d[i].x, r = d[i + 1].x, b = d[i].y; else l = d[i + 1].x, r = d[i].x, b = d[i + 1].y; for (j = l; j <= r; j++) { Max(U[j], b + (j - l) * k); Min(D[j], b + (j - l) * k); } } } double sum, sum2, cnt, res; sum = sum2 = cnt = res = 0.; for (i = 0; i <= mx; i++) { double c = floor(U[i]) - ceil(D[i]) + 1.; res += (cnt * i * i - 2. * sum * i + sum2) * c; sum += c * i; sum2 += c * i * i; cnt += c; } ans += res / (cnt * (cnt - 1)); } int main() { scanf("%d", &n); int i, mx, my; mx = my = 0x7fffffff; for (i = 0; i < n; i++) { scanf("%d%d", &d[i].x, &d[i].y); if (d[i].x < mx) mx = d[i].x; if (d[i].y < my) my = d[i].y; } for (i = 0; i < n; i++) { d[i].x -= mx; d[i].y -= my; } work(); for (i = 0; i < n; i++) swap(d[i].x, d[i].y); work(); printf("%f\n", ans); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { static int r, sign; static char c; r = 0, c = getchar(), sign = 1; while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') sign = -1, c = getchar(); while (c >= '0' && c <= '9') r = r * 10 + (c - '0'), c = getchar(); return r * sign; } template <typename T> inline void print(T *a, int n) { for (int i = 1; i < n; ++i) cout << a[i] << " "; cout << a[n] << endl; } struct point { int x, y; inline void read() { scanf("%d%d", &x, &y); } } p, q, t; int n, u[2000010 + 1], d[2000010 + 1], l[2000010 + 1], r[2000010 + 1], U, R, L, D; inline void process(const point &p, const point &q) { if (p.x == q.x) { u[p.x + 1000000] = max(u[p.x + 1000000], max(p.y, q.y)); d[p.x + 1000000] = min(d[p.x + 1000000], min(p.y, q.y)); } else { double ma = max(p.x, q.x), mi = min(p.x, q.x), s = p.x < q.x ? p.y : q.y; for (int i = mi; i <= ma; ++i) { double y = s + (double)(i - mi) * (q.y - p.y) / (q.x - p.x); u[i + 1000000] = max(u[i + 1000000], (int)floor(y)); d[i + 1000000] = min(d[i + 1000000], (int)ceil(y)); } } if (p.y == q.y) { r[p.y + 1000000] = max(r[p.y + 1000000], max(p.x, q.x)); l[p.y + 1000000] = min(l[p.y + 1000000], min(p.x, q.x)); } else { double ma = max(p.y, q.y), mi = min(p.y, q.y), s = p.y < q.y ? p.x : q.x; for (int i = mi; i <= ma; ++i) { double x = s + (double)(i - mi) * (q.x - p.x) / (q.y - p.y); r[i + 1000000] = max(r[i + 1000000], (int)floor(x)); l[i + 1000000] = min(l[i + 1000000], (int)ceil(x)); } } } inline void process(const point &p) { U = max(U, p.y), D = min(D, p.y); R = max(R, p.x), L = min(L, p.x); } double s[4][2000010 + 1]; double solve(int n) { for (int i = 0; i < 4; ++i) s[i][n + 1] = 0; for (int i = n; i > 0; --i) s[1][i] = s[1][i + 1] + s[0][i]; if (s[1][1] <= 1) return 0.0; for (int i = n; i > 0; --i) s[2][i] = s[2][i + 1] + 2 * s[1][i] - s[0][i]; double tot = s[1][1] * (s[1][1] - 1); for (int i = n; i > 0; --i) s[2][i] /= tot; for (int i = n; i > 0; --i) s[3][i] = s[3][i + 1] + s[2][i]; double ret = 0.0; for (int i = n - 1; i > 0; --i) ret += s[0][i] * s[3][i + 1]; return ret; } int main(int argc, char *argv[]) { for (int i = 0; i <= 2000010; ++i) u[i] = r[i] = INT_MIN, d[i] = l[i] = INT_MAX; U = R = INT_MIN, D = L = INT_MAX; scanf("%d", &n); p.read(), t = p, process(t); for (int i = 2; i <= n; ++i) { q.read(), process(q); process(p, q); p = q; } process(q, t); double ans = 0.0; int cnt = 0; for (int i = L; i <= R; ++i) s[0][++cnt] = (double)(u[i + 1000000] - d[i + 1000000] + 1); ans += solve(cnt); cnt = 0; for (int i = D; i <= U; ++i) s[0][++cnt] = (double)(r[i + 1000000] - l[i + 1000000] + 1); ans += solve(cnt); printf("%.10lf\n", ans); fclose(stdin); fclose(stdout); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, x[100007], y[100007]; double p[2000007], sum[2000007], a[2000007], b[2000007], ans = 0; void solve() { int up = 0, dw = 2e6 + 1, id = 0; int l = 0, r = 0; for (int i = 0; i < n; i++) { up = max(up, x[i]); if (dw > x[i]) { dw = x[i]; id = i; } } l = r = id; memset(p, 0, sizeof(p)); memset(sum, 0, sizeof(sum)); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); double total = 0, ret = 0; for (int i = dw; i <= up; i++) { while (x[(l - 1 + n) % n] < i) l = (l - 1 + n) % n; while (x[(r + 1) % n] < i) r = (r + 1) % n; int lef = 0, rig = 2e6; vector<double> pt; if (x[(l - 1 + n) % n] == x[l]) { pt.push_back(y[l]), pt.push_back(y[(l - 1 + n) % n]); } else { int pv = (l - 1 + n) % n; pt.push_back(1.0 * (y[pv] - y[l]) / (x[pv] - x[l]) * (i - x[l]) + 1.0 * y[l]); } if (x[r] == x[(r + 1) % n]) { pt.push_back(y[r]), pt.push_back(y[(r + 1) % n]); } else { int pv = (r + 1) % n; pt.push_back(1.0 * (y[pv] - y[r]) / (x[pv] - x[r]) * (i - x[r]) + 1.0 * y[r]); } sort(pt.begin(), pt.end()); lef = (int)ceil(pt[0]); rig = (int)pt[(int)pt.size() - 1]; p[i] = max(0, rig - lef + 1); total += p[i]; } total = total * (total - 1) / 2LL; for (int i = dw; i <= up; i++) { p[i] /= total; sum[i] = sum[i - 1] + 2.0 * p[i]; } for (int i = dw + 1; i <= up; i++) { a[i] = a[i - 1] + p[i - 1] + b[i - 1] + sum[i - 2]; b[i] = b[i - 1] + p[i - 1] + sum[i - 2]; ret = ret + p[i] * total * a[i]; } ans += ret; } int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; x[i] += 1e6 + 1; y[i] += 1e6 + 1; } solve(); for (int i = 0; i < n; i++) swap(x[i], y[i]); solve(); cout << (fixed) << setprecision(15) << ans / 2.0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e5, M = 2e6; struct CPOINT { int x, y; int& operator[](int id) { return id == 1 ? x : y; } bool operator<(const CPOINT& Cb) const& { if (x == Cb.x) return y < Cb.y; return x < Cb.x; } } pnt[N + 3]; double Tex(CPOINT Ca, CPOINT Cb) { return Ca.x == Cb.x ? (Ca.y > Cb.y ? -1e9 : 1e9) : double(Ca.y - Cb.y) / (Ca.x - Cb.x); } struct SSTACK { int stk[N + 3], top; void Push(int Vv) { stk[++top] = Vv; } int Size() { return top; } void Pop() { stk[top--] = 0; } int Fir() { return stk[top]; } int Sec() { return stk[top - 1]; } int& operator[](int id) { return stk[id]; } }; SSTACK Sup, Slow; int n; int Cn[M + 3]; long long Rcnt; int GetLowY(CPOINT Ca, CPOINT Cb, int x) { if (x == Ca.x) { if (Cb.x == Ca.x) return max(Cb.y, Ca.y); return Ca.y; } int Rl = -1, Rr = 2e6 + 1; while (Rl + 1 < Rr) { int Rm = (Rl + Rr) >> 1; if (1ll * (Rm - Ca.y) * (Cb.x - Ca.x) <= 1ll * (Cb.y - Ca.y) * (x - Ca.x)) Rl = Rm; else Rr = Rm; } return Rl; } int GetHigY(CPOINT Ca, CPOINT Cb, int x) { if (x == Ca.x) { if (Cb.x == Ca.x) return min(Cb.y, Ca.y); return Ca.y; } int Rl = -1, Rr = 2e6 + 1; while (Rl + 1 < Rr) { int Rm = (Rl + Rr) >> 1; if (1ll * (Rm - Ca.y) * (Cb.x - Ca.x) >= 1ll * (Cb.y - Ca.y) * (x - Ca.x)) Rr = Rm; else Rl = Rm; } return Rr; } long double Solve() { sort(pnt + 1, pnt + 1 + n); while (Sup.Size()) Sup.Pop(); while (Slow.Size()) Slow.Pop(); Sup.Push(1); Sup.Push(2); Slow.Push(1); Slow.Push(2); for (int i = 3; i <= n; i++) { while (Sup.Size() >= 2 && Tex(pnt[Sup.Sec()], pnt[Sup.Fir()]) <= Tex(pnt[Sup.Fir()], pnt[i])) Sup.Pop(); Sup.Push(i); while (Slow.Size() >= 2 && Tex(pnt[Slow.Sec()], pnt[Slow.Fir()]) >= Tex(pnt[Slow.Fir()], pnt[i])) Slow.Pop(); Slow.Push(i); } int Lef = pnt[Sup[1]][1], Rig = pnt[Sup.Fir()][1]; memset(Cn, 0, sizeof Cn); long double totCn = 0, Rs = 0, totCni = 0, totCni2 = 0; int Vup = 2, Vlow = 2; Rcnt = 0; for (int i = Lef; i <= Rig; i++) { while (i > pnt[Sup[Vup]][1]) Vup++; while (i > pnt[Slow[Vlow]][1]) Vlow++; Cn[i] = GetLowY(pnt[Sup[Vup - 1]], pnt[Sup[Vup]], i) - GetHigY(pnt[Slow[Vlow - 1]], pnt[Slow[Vlow]], i) + 1; Rcnt += Cn[i]; totCn += (long double)Cn[i]; totCni += (long double)i * Cn[i]; totCni2 += (long double)i * i * Cn[i]; } Rs = (totCn * totCni2 - totCni * totCni); return Rs; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &pnt[i][1], &pnt[i][2]); pnt[i][1] += (int)1e6; pnt[i][2] += (int)1e6; } long double Vans = Solve(); for (int i = 1; i <= n; i++) swap(pnt[i][1], pnt[i][2]); Vans += Solve(); printf("%.10f\n", double(Vans / Rcnt / (Rcnt - 1))); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; typedef struct point { int x, y; point(int x0, int y0) { x = x0; y = y0; } } PT; class Line { public: double A, B, C; Line(double x1, double y1, double x2, double y2) { A = y2 - y1; B = x1 - x2; C = A * x1 + B * y1; } double getY(double x) { return (C - A * x) / B; } double getX(double y) { return (C - B * y) / C; } }; double horizontal[2000005][2], result; int integralHorizontalPoints[2000005]; vector<PT> polygon; double totalArea, totalIntegreal; void preprocess(int n) { int i, j, l, r, k, x, y, minX = 2000005, maxX = -2000005; double difference = 0.0, doubleDiff = 0.0, oldArea = 0.0; for (i = 0; i < 2000005; i++) { horizontal[i][0] = 1.0 * 2000005; horizontal[i][1] = -1.0 * 2000005; } for (i = 0; i < n; i++) { minX = min(minX, polygon[i].x); maxX = max(maxX, polygon[i].x); j = i + 1; if (j == n) j = 0; Line L(1.0 * polygon[i].x, 1.0 * polygon[i].y, 1.0 * polygon[j].x, 1.0 * polygon[j].y); l = min(polygon[i].x, polygon[j].x); r = max(polygon[i].x, polygon[j].x); if (l == r) { if (polygon[i].y < polygon[j].y) { x = polygon[i].y; y = polygon[j].y; } else { x = polygon[j].y; y = polygon[i].y; } horizontal[l][0] = min(horizontal[l][0], 1.0 * x); horizontal[l][1] = max(horizontal[l][1], 1.0 * y); } else { for (k = l; k <= r; k++) { horizontal[k][0] = min(horizontal[k][0], L.getY(k)); horizontal[k][1] = max(horizontal[k][1], L.getY(k)); } } } for (i = minX; i <= maxX; i++) { integralHorizontalPoints[i] = floor(horizontal[i][1]) - ceil(horizontal[i][0]) + 1; totalIntegreal += 1.0 * integralHorizontalPoints[i]; } oldArea = 1.0 * integralHorizontalPoints[minX]; totalArea += 1.0 * oldArea * integralHorizontalPoints[minX + 1]; difference = integralHorizontalPoints[minX]; for (i = minX + 2; i <= maxX; i++) { doubleDiff += 2.0 * integralHorizontalPoints[i - 2]; difference += doubleDiff + 1.0 * integralHorizontalPoints[i - 1]; oldArea += difference; totalArea += 1.0 * oldArea * integralHorizontalPoints[i]; } return; } double nc2(double n) { return n * (n - 1.0); } int main() { int i, j, t, n, m, k, l, r, temp, mini, maxi, flag, cnt, x, y; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &l, &r); l += 1000000; r += 1000000; PT foo(l, r); polygon.push_back(foo); } preprocess(n); for (i = 0; i < n; i++) swap(polygon[i].x, polygon[i].y); preprocess(n); totalIntegreal /= 2.0; result = totalArea / nc2(totalIntegreal); printf("%.8lf\n", result); return 0; }
10
CPP