problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02763
C++
Runtime Error
// Catchharsh #include <bits/stdc++.h> #define ll long long int #define ld long double #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define F first #define S second #define sz(x) x.size() #define all(x) x.begin(), x.end() #define pb push_back #define endl '\n' #define see(x) cout << #x << " = " << x << endl const ll MOD = 1e9 + 7; const ll INF = 1011111111; const ll LLINF = 1000111000111000111LL; const ld EPS = 1e-10; const ld PI = 3.14159265358979323; using namespace std; ll power(ll base, ll exponent) { ll ans = 1; // base%=MOD; // exponent%=(MOD-1); while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base); base = (1LL * base * base); exponent >>= 1; } return ans; } const ll N = 2 * 1e5; struct tt { ll ar[26]; }; tt vii; // int ar[100005]; string s; tt tree[4 * N]; tt merge(tt a, tt b) { tt final; for (ll i = 0; i < 26; i++) final.ar[i] = a.ar[i] + b.ar[i]; return final; } void build(ll node, ll start, ll end) { if (start == end) { tree[node].ar[s[start] - 'a']++; return; } else { ll mid = (start + end) / 2; build(2 * node, start, mid); build(2 * node + 1, mid + 1, end); tree[node] = merge(tree[2 * node], tree[2 * node + 1]); } } tt query(ll l, ll r, ll start, ll end, ll node) { if (end < l || start > r) // checking whether range is out of L and R { return vii; } else if (l <= start && end <= r) // if the range is completely under L and R { return tree[node]; } else // if there is partial overlap between range and L and R { ll mid = (start + end) / 2; tt p1 = query(l, r, start, mid, 2 * node); // Checking for answer in left part tt p2 = query(l, r, mid + 1, end, 2 * node + 1); // Checking for answer in right part return merge(p1, p2); } } void update(ll idx, char c, ll node, ll start, ll end) { ll mid = (start + end) / 2; if (start == end) { tree[node].ar[s[start] - 'a']--; s[start] = c; tree[node].ar[s[start] - 'a']++; } else { if (start <= idx && idx <= mid) update(idx, c, 2 * node, start, mid); else update(idx, c, 2 * node + 1, mid + 1, end); tree[node] = merge(tree[2 * node], tree[2 * node + 1]); } } int32_t main() { IOS; ll n; cin >> n; cin >> s; build(1, 0, n - 1); ll i, j, k, q; cin >> q; while (q--) { ll x; cin >> x; if (x == 1) { ll id; char ch; cin >> id >> ch; update(id - 1, ch, 1, 0, n - 1); } else { ll ans = 0; ll l, r; cin >> l >> r; tt ap = query(l - 1, r - 1, 0, n - 1, 1); for (i = 0; i < 26; i++) if (ap.ar[i]) ans++; cout << ans << endl; } } cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'; }
// Catchharsh #include <bits/stdc++.h> #define ll long long int #define ld long double #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define F first #define S second #define sz(x) x.size() #define all(x) x.begin(), x.end() #define pb push_back #define endl '\n' #define see(x) cout << #x << " = " << x << endl const ll MOD = 1e9 + 7; const ll INF = 1011111111; const ll LLINF = 1000111000111000111LL; const ld EPS = 1e-10; const ld PI = 3.14159265358979323; using namespace std; ll power(ll base, ll exponent) { ll ans = 1; // base%=MOD; // exponent%=(MOD-1); while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base); base = (1LL * base * base); exponent >>= 1; } return ans; } const ll N = 5 * 1e5 + 5; struct tt { ll ar[26]; }; tt vii; // int ar[100005]; string s; tt tree[4 * N]; tt merge(tt a, tt b) { tt final; for (ll i = 0; i < 26; i++) final.ar[i] = a.ar[i] + b.ar[i]; return final; } void build(ll node, ll start, ll end) { if (start == end) { tree[node].ar[s[start] - 'a']++; return; } else { ll mid = (start + end) / 2; build(2 * node, start, mid); build(2 * node + 1, mid + 1, end); tree[node] = merge(tree[2 * node], tree[2 * node + 1]); } } tt query(ll l, ll r, ll start, ll end, ll node) { if (end < l || start > r) // checking whether range is out of L and R { return vii; } else if (l <= start && end <= r) // if the range is completely under L and R { return tree[node]; } else // if there is partial overlap between range and L and R { ll mid = (start + end) / 2; tt p1 = query(l, r, start, mid, 2 * node); // Checking for answer in left part tt p2 = query(l, r, mid + 1, end, 2 * node + 1); // Checking for answer in right part return merge(p1, p2); } } void update(ll idx, char c, ll node, ll start, ll end) { ll mid = (start + end) / 2; if (start == end) { tree[node].ar[s[start] - 'a']--; s[start] = c; tree[node].ar[s[start] - 'a']++; } else { if (start <= idx && idx <= mid) update(idx, c, 2 * node, start, mid); else update(idx, c, 2 * node + 1, mid + 1, end); tree[node] = merge(tree[2 * node], tree[2 * node + 1]); } } int32_t main() { IOS; ll n; cin >> n; cin >> s; build(1, 0, n - 1); ll i, j, k, q; cin >> q; while (q--) { ll x; cin >> x; if (x == 1) { ll id; char ch; cin >> id >> ch; update(id - 1, ch, 1, 0, n - 1); } else { ll ans = 0; ll l, r; cin >> l >> r; tt ap = query(l - 1, r - 1, 0, n - 1, 1); for (i = 0; i < 26; i++) if (ap.ar[i]) ans++; cout << ans << endl; } } cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'; }
replace
33
34
33
34
-11
p02763
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++) #define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout << fixed << setprecision(15); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; int main() { Init(); ll n, q; string s; cin >> n >> s >> q; map<char, set<ll>> d; rep(i, n) d[s[i]].insert(i); rep(i, q) { ll cmd; cin >> cmd; if (cmd == 1) { ll idx; char c; cin >> idx >> c; idx--; if (s[idx] == c) continue; d[s[idx]].erase(idx); s[idx] = c; d[c].insert(idx); } else if (cmd == 2) { ll l, r, cnt = 0; cin >> l >> r; l--; r--; for (auto p : d) { auto it = p.second.lower_bound(l); if (it == p.second.end()) continue; if (*it <= r) cnt++; } cout << cnt << endl; } } }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++) #define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout << fixed << setprecision(15); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; int main() { Init(); ll n, q; string s; cin >> n >> s >> q; map<char, set<ll>> d; rep(i, n) d[s[i]].insert(i); rep(i, q) { ll cmd; cin >> cmd; if (cmd == 1) { ll idx; char c; cin >> idx >> c; idx--; if (s[idx] == c) continue; d[s[idx]].erase(idx); s[idx] = c; d[c].insert(idx); } else if (cmd == 2) { ll l, r, cnt = 0; cin >> l >> r; l--; r--; for (char c = 'a'; c <= 'z'; c++) { auto it = d[c].lower_bound(l); if (it == d[c].end()) continue; if (*it <= r) cnt++; } cout << cnt << endl; } } }
replace
60
63
60
63
TLE
p02763
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; int main() { Int N, Q; string s; cin >> N >> s >> Q; set<Int> S[26]; rep(i, N) { rep(j, 26) { if (s[i] == 'a' + j) S[j].insert(i); S[j].insert(N); } } rep(k, Q) { int a; cin >> a; if (a == 1) { Int i; char c; cin >> i >> c; i--; rep(j, 26) { if (S[j].find(i) == S[j].end()) { } else S[j].erase(i); } S[c - 'a'].insert(i); } else if (a == 2) { Int l, r; cin >> l >> r; l--; r--; int cnt = 0; rep(j, 26) { if (*S[j].lower_bound(l) <= r) cnt++; } cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; int main() { Int N, Q; string s; cin >> N >> s >> Q; set<Int> S[26]; rep(i, N) { S[s[i] - 'a'].insert(i); } rep(i, 26) S[i].insert(N); rep(k, Q) { int a; cin >> a; if (a == 1) { Int i; char c; cin >> i >> c; i--; rep(j, 26) { if (S[j].find(i) == S[j].end()) { } else S[j].erase(i); } S[c - 'a'].insert(i); } else if (a == 2) { Int l, r; cin >> l >> r; l--; r--; int cnt = 0; rep(j, 26) { if (*S[j].lower_bound(l) <= r) cnt++; } cout << cnt << endl; } } return 0; }
replace
13
20
13
15
TLE
p02763
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define INF 1000000000000 typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vin; typedef pair<ll, ll> P; typedef vector<P> vp; int MOD = 1000000007; struct edge { int to, cost; }; int modpow(int a, int x) { if (a < 0) a += MOD; int ans = 1; while (x > 0) { if (x & 1) ans = ans * a % MOD; a = a * a % MOD; x >>= 1; } return ans; } int gyaku(int n) { return modpow(n, MOD - 2); } auto factor(int n) { map<int, int> res; for (int i = 2; i * i <= n; i++) { for (; n % i == 0; n /= i) res[i]++; } if (n > 1) res[n]++; return res; } //////////////////////////////////////////////////////////// signed main() { int n; cin >> n; vector<char> s(n); rep(i, n) cin >> s[i]; int q; cin >> q; set<int> sc[30]; rep(i, n) { int c = s[i] - 'a'; sc[c].insert(i); } int a; rep(i, q) { cin >> a; if (a == 1) { int g; char c; cin >> g >> c; g--; int t = s[g] - 'a'; s[g] = c; sc[t].erase(g); sc[c - 'a'].insert(g); } if (a == 2) { int l, r; cin >> l >> r; l--; r--; int ans = 0; rep(j, 26) { if (!sc[j].empty()) { auto idx = lower_bound(sc[j].begin(), sc[j].end(), l); if (r >= *idx && idx != sc[j].end()) { ans++; } } } cout << ans << endl; } } }
#include <algorithm> #include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define INF 1000000000000 typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vin; typedef pair<ll, ll> P; typedef vector<P> vp; int MOD = 1000000007; struct edge { int to, cost; }; int modpow(int a, int x) { if (a < 0) a += MOD; int ans = 1; while (x > 0) { if (x & 1) ans = ans * a % MOD; a = a * a % MOD; x >>= 1; } return ans; } int gyaku(int n) { return modpow(n, MOD - 2); } auto factor(int n) { map<int, int> res; for (int i = 2; i * i <= n; i++) { for (; n % i == 0; n /= i) res[i]++; } if (n > 1) res[n]++; return res; } //////////////////////////////////////////////////////////// signed main() { int n; cin >> n; vector<char> s(n); rep(i, n) cin >> s[i]; int q; cin >> q; set<int> sc[30]; rep(i, n) { int c = s[i] - 'a'; sc[c].insert(i); } int a; rep(i, q) { cin >> a; if (a == 1) { int g; char c; cin >> g >> c; g--; int t = s[g] - 'a'; s[g] = c; sc[t].erase(g); sc[c - 'a'].insert(g); } if (a == 2) { int l, r; cin >> l >> r; l--; r--; int ans = 0; rep(j, 26) { if (!sc[j].empty()) { auto idx = sc[j].lower_bound(l); if (r >= *idx && idx != sc[j].end()) { ans++; } } } cout << ans << endl; } } }
replace
80
81
80
81
TLE
p02763
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1e15; int main() { ll n; cin >> n; string s; cin >> s; ll q; cin >> q; vector<set<ll>> st(26); REP(i, 26) st[i].insert(INF); REP(i, n) { st[s[i] - 'a'].insert(i); } while (q--) { ll qn; cin >> qn; if (qn == 1) { ll i; char c; cin >> i >> c; --i; st[s[i] - 'a'].erase(i); s[i] = c; st[s[i] - 'a'].insert(i); } else { ll ans = 0; ll l, r; cin >> l >> r; --l, --r; REP(k, 26) { auto itl = lower_bound(ALL(st[k]), l); if (*itl == INF) continue; if (*itl <= r) ++ans; } cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1e15; int main() { ll n; cin >> n; string s; cin >> s; ll q; cin >> q; vector<set<ll>> st(26); REP(i, 26) st[i].insert(INF); REP(i, n) { st[s[i] - 'a'].insert(i); } while (q--) { ll qn; cin >> qn; if (qn == 1) { ll i; char c; cin >> i >> c; --i; st[s[i] - 'a'].erase(i); s[i] = c; st[s[i] - 'a'].insert(i); } else { ll ans = 0; ll l, r; cin >> l >> r; --l, --r; REP(k, 26) { auto itl = st[k].lower_bound(l); if (*itl <= r) ++ans; } cout << ans << endl; } } return 0; }
replace
42
46
42
43
TLE
p02763
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long; using Pll = pair<ll, ll>; using Pii = pair<int, int>; constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 60; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; template <typename T> class BIT { public: int n; vector<T> bit; BIT(int n) : n(n) { bit.resize(n); fill(bit.begin(), bit.end(), (T)0); } void add(int idx, T x) { for (int i = idx; i <= this->n; i += i & -i) bit[i] += x; } // bit[1]からbit[end]までの和 (閉区間) T sum(int end) { T ret = (T)0; for (int i = end; i >= 1; i -= i & -i) ret += bit[i]; return ret; } T count_swap(vector<int> v) { T ret = (T)0; for (int i = 1; i <= n; ++i) { add(v[i], 1); ret += i - sum(v[i]); } return ret; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; vector<BIT<int>> trees(26, BIT<int>(n + 1)); for (int i = 0; i < n; ++i) { trees[s[i] - 'a'].add(i + 1, 1); } int q, query; cin >> q; for (int i = 0; i < q; ++i) { cin >> query; if (query == 1) { int qi; char qc; cin >> qi >> qc; trees[s[qi - 1] - 'a'].add(qi, -1); s[qi - 1] = qc; trees[qc - 'a'].add(qi, 1); } else { int ql, qr, ans = 0; cin >> ql >> qr; for (int j = 0; j < 26; ++j) { if (trees[j].sum(qr) - trees[j].sum(ql - 1) > 0) { ++ans; } } cout << ans << endl; } } }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long; using Pll = pair<ll, ll>; using Pii = pair<int, int>; constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 60; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; template <typename T> class BIT { public: int n; vector<T> bit; BIT(int n) : n(n) { bit.resize(n); fill(bit.begin(), bit.end(), (T)0); } void add(int idx, T x) { for (int i = idx; i <= this->n; i += i & -i) bit[i] += x; } // bit[1]からbit[end]までの和 (閉区間) T sum(int end) { T ret = (T)0; for (int i = end; i >= 1; i -= i & -i) ret += bit[i]; return ret; } T count_swap(vector<int> v) { T ret = (T)0; for (int i = 1; i <= n; ++i) { add(v[i], 1); ret += i - sum(v[i]); } return ret; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; vector<BIT<int>> trees(26, BIT<int>(n + 10)); for (int i = 0; i < n; ++i) { trees[s[i] - 'a'].add(i + 1, 1); } int q, query; cin >> q; for (int i = 0; i < q; ++i) { cin >> query; if (query == 1) { int qi; char qc; cin >> qi >> qc; trees[s[qi - 1] - 'a'].add(qi, -1); s[qi - 1] = qc; trees[qc - 'a'].add(qi, 1); } else { int ql, qr, ans = 0; cin >> ql >> qr; for (int j = 0; j < 26; ++j) { if (trees[j].sum(qr) - trees[j].sum(ql - 1) > 0) { ++ans; } } cout << ans << endl; } } }
replace
73
74
73
74
0
p02763
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const int iinf = 1 << 28; const long long llinf = 1ll << 60; const double PI = 3.14159265; // int st[1050000][26]; // const int mid = 524288; int st[16][26]; const int mid = 8; void upd(int idx, char c) { int v = c - 'a'; for (int i = 0; i < 26; ++i) { if (st[mid + idx][i]) st[mid + idx][i]--; } st[mid + idx][v] = 1; for (int i = (mid + idx) >> 1; i > 0; i >>= 1) { for (int j = 0; j < 26; ++j) { st[i][j] = st[i << 1][j] + st[(i << 1) + 1][j]; } } } void getv(int idx, int l, int r, int ll, int rr, int nelements, int c[26]) { if (l > rr || r < ll) return; if (l == ll && r == rr) { for (int i = 0; i < 26; ++i) c[i] = st[idx][i]; return; } int c1[26]; for (int i = 0; i < 26; ++i) c1[i] = 0; getv(idx << 1, l, min(r, ll + (nelements >> 1) - 1), ll, ll + (nelements >> 1) - 1, nelements >> 1, c1); int c2[26]; for (int i = 0; i < 26; ++i) c2[i] = 0; getv((idx << 1) + 1, max(l, ll + (nelements >> 1)), r, ll + (nelements >> 1), rr, nelements >> 1, c2); for (int i = 0; i < 26; ++i) { c[i] = c1[i] + c2[i]; } } void pr() { for (int i = 0; i < 26; ++i) { char c = 'a' + i; cout << c << ": "; for (int j = 1; j < 16; ++j) { cout << st[j][i]; } cout << "\n"; } } void work() { int n; cin >> n; for (int i = 0; i < n; ++i) { char c; cin >> c; int v = c - 'a'; st[i + mid][v]++; } for (int i = mid - 1; i > 0; --i) { for (int j = 0; j < 26; ++j) { st[i][j] = st[i << 1][j] + st[(i << 1) + 1][j]; } } int q; cin >> q; for (int i = 0; i < q; ++i) { int t; cin >> t; if (t == 1) { int a; char b; cin >> a >> b; upd(a - 1, b); } else { int a, b; cin >> a >> b; int c[26]; for (int i = 0; i < 26; ++i) c[i] = 0; getv(1, a - 1, b - 1, 0, mid - 1, mid, c); int ans = 0; for (int i = 0; i < 26; ++i) { if (c[i]) ++ans; } cout << ans << endl; // pr(); } } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const int iinf = 1 << 28; const long long llinf = 1ll << 60; const double PI = 3.14159265; int st[1050000][26]; const int mid = 524288; // int st[16][26]; // const int mid = 8; void upd(int idx, char c) { int v = c - 'a'; for (int i = 0; i < 26; ++i) { if (st[mid + idx][i]) st[mid + idx][i]--; } st[mid + idx][v] = 1; for (int i = (mid + idx) >> 1; i > 0; i >>= 1) { for (int j = 0; j < 26; ++j) { st[i][j] = st[i << 1][j] + st[(i << 1) + 1][j]; } } } void getv(int idx, int l, int r, int ll, int rr, int nelements, int c[26]) { if (l > rr || r < ll) return; if (l == ll && r == rr) { for (int i = 0; i < 26; ++i) c[i] = st[idx][i]; return; } int c1[26]; for (int i = 0; i < 26; ++i) c1[i] = 0; getv(idx << 1, l, min(r, ll + (nelements >> 1) - 1), ll, ll + (nelements >> 1) - 1, nelements >> 1, c1); int c2[26]; for (int i = 0; i < 26; ++i) c2[i] = 0; getv((idx << 1) + 1, max(l, ll + (nelements >> 1)), r, ll + (nelements >> 1), rr, nelements >> 1, c2); for (int i = 0; i < 26; ++i) { c[i] = c1[i] + c2[i]; } } void pr() { for (int i = 0; i < 26; ++i) { char c = 'a' + i; cout << c << ": "; for (int j = 1; j < 16; ++j) { cout << st[j][i]; } cout << "\n"; } } void work() { int n; cin >> n; for (int i = 0; i < n; ++i) { char c; cin >> c; int v = c - 'a'; st[i + mid][v]++; } for (int i = mid - 1; i > 0; --i) { for (int j = 0; j < 26; ++j) { st[i][j] = st[i << 1][j] + st[(i << 1) + 1][j]; } } int q; cin >> q; for (int i = 0; i < q; ++i) { int t; cin >> t; if (t == 1) { int a; char b; cin >> a >> b; upd(a - 1, b); } else { int a, b; cin >> a >> b; int c[26]; for (int i = 0; i < 26; ++i) c[i] = 0; getv(1, a - 1, b - 1, 0, mid - 1, mid, c); int ans = 0; for (int i = 0; i < 26; ++i) { if (c[i]) ++ans; } cout << ans << endl; // pr(); } } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); work(); return 0; }
replace
8
12
8
12
0
p02763
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define popcnt(a) __builtin_popcount(a) #define error(args...) \ { \ cerr << "LINE " << __LINE__; \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ cerr << endl; \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << ' ' << *it << " = " << a; err(++it, args...); } typedef long long ll; const int N = 26, M = 1e5 + 9, OO = 0x3f3f3f3f, MOD = 1e9 + 7; set<int> arr[N]; char str[M]; int main() { int n; scanf("%d", &n); scanf("%s", str); for (int i = 0; i < n; ++i) arr[str[i] - 'a'].insert(i); int m; scanf("%d", &m); error(m); while (m--) { int op, l; scanf("%d%d", &op, &l); l--; if (op == 1) { char c; scanf(" %c", &c); arr[str[l] - 'a'].erase(l); arr[c - 'a'].insert(l); str[l] = c; } else { int r, ans = 0; scanf("%d", &r); r--; for (int i = 0; i < 26; ++i) if (!arr[i].empty() && arr[i].lower_bound(l) != arr[i].end() && *arr[i].lower_bound(l) <= r) ans++; printf("%d\n", ans); } } #ifdef _LOCAL_DEFINE cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define popcnt(a) __builtin_popcount(a) #define error(args...) \ { \ cerr << "LINE " << __LINE__; \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ cerr << endl; \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << ' ' << *it << " = " << a; err(++it, args...); } typedef long long ll; const int N = 26, M = 5e5 + 1, OO = 0x3f3f3f3f, MOD = 1e9 + 7; set<int> arr[N]; char str[M]; int main() { int n; scanf("%d", &n); scanf("%s", str); for (int i = 0; i < n; ++i) arr[str[i] - 'a'].insert(i); int m; scanf("%d", &m); error(m); while (m--) { int op, l; scanf("%d%d", &op, &l); l--; if (op == 1) { char c; scanf(" %c", &c); arr[str[l] - 'a'].erase(l); arr[c - 'a'].insert(l); str[l] = c; } else { int r, ans = 0; scanf("%d", &r); r--; for (int i = 0; i < 26; ++i) if (!arr[i].empty() && arr[i].lower_bound(l) != arr[i].end() && *arr[i].lower_bound(l) <= r) ans++; printf("%d\n", ans); } } #ifdef _LOCAL_DEFINE cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl; #endif return 0; }
replace
21
22
21
22
0
LINE 39 m = 6
p02763
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long const int mod = 1000000007; const int MOD = 998244353; const ll INF = 1000000000000000000; int main() { int N, Q; string S; cin >> N >> S >> Q; set<int> st[26]; for (int i = 0; i < N; i++) { st[S[i] - 'a'].insert(i); } for (int i = 0; i < 26; i++) { st[i].insert(N); } while (Q--) { int q; cin >> q; if (q == 1) { int i; char c; cin >> i >> c; i--; st[S[i] - 'a'].erase(i); S[i] = c; st[S[i] - 'a'].insert(i); } else { int l, r; cin >> l >> r; l--; r--; int ans = 0; for (int i = 0; i < 26; i++) { auto itr = lower_bound(st[i].begin(), st[i].end(), l); int num = *itr; if (num <= r) ans++; } cout << ans << endl; } } }
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long const int mod = 1000000007; const int MOD = 998244353; const ll INF = 1000000000000000000; int main() { int N, Q; string S; cin >> N >> S >> Q; set<int> st[26]; for (int i = 0; i < N; i++) { st[S[i] - 'a'].insert(i); } for (int i = 0; i < 26; i++) { st[i].insert(N); } while (Q--) { int q; cin >> q; if (q == 1) { int i; char c; cin >> i >> c; i--; st[S[i] - 'a'].erase(i); S[i] = c; st[S[i] - 'a'].insert(i); } else { int l, r; cin >> l >> r; l--; r--; int ans = 0; for (int i = 0; i < 26; i++) { auto itr = st[i].lower_bound(l); int num = *itr; if (num <= r) ans++; } cout << ans << endl; } } }
replace
46
47
46
47
TLE
p02763
C++
Runtime Error
#pragma GCC optimize("O3", "unroll-loops") // #pragma GCC target("avx2") #include <bits/stdc++.h> #include <stdio.h> using namespace std; #define ull unsigned long long #define si short int #define ll long long #define ld long double #define pb push_back #define pii pair<int, int> #define pil pair<int, ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define piii pair<pair<int, int>, int> #define all(vec) vec.begin(), vec.end() #define piiii pair<pair<int, int>, pair<int, int>> #define fr(a, from, c) for (int a = (from); (a) < (c); (a)++) /*-----------------------------------------------------SegTree---------------------------------------------*/ int mxn11 = (int)(2e5 + 1); vector<vector<int>> t(26, vector<int>(4 * mxn11)); string s; void build(int v, int vl, int vr, int i) { if (vl == vr) { if (s[vl] - 'a' == i) { t[i][v] = 1; } } else { int tmp = (vl + vr) >> 1; build(2 * v, vl, tmp, i); build(2 * v + 1, tmp + 1, vr, i); t[i][v] = t[i][2 * v] + t[i][2 * v + 1]; } } int get(int v, int vl, int vr, int l, int r, int i) { if (l > r) return 0; if (vl == l && vr == r) { return t[i][v]; } int tmp = (vl + vr) >> 1; ll a = get(2 * v, vl, tmp, l, min(tmp, r), i); ll b = get(2 * v + 1, tmp + 1, vr, max(tmp + 1, l), r, i); return a + b; } void update(int v, int vl, int vr, int pos, int what) { if (vl == vr) { for (int i = 0; i < 26; i++) { t[i][v] = (what == i) ? 1 : 0; } return; } int tmp = (vl + vr) >> 1; if (pos <= tmp) update(2 * v, vl, tmp, pos, what); else update(2 * v + 1, tmp + 1, vr, pos, what); for (int i = 0; i < 26; i++) { t[i][v] = t[i][2 * v + 1] + t[i][2 * v]; } } /*-----------------------------------------------------SegTree---------------------------------------------*/ /*-----------------------------------------------------MATH------------------------------------------------*/ inline ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll pwm(ll xx, ll pow, ll MD) { if (pow < 0) { pow = pow % (MD - 1) + MD - 1; } ll mlt = 1; while (pow) { if (pow & 1) { mlt *= xx; mlt %= MD; } xx *= xx; pow >>= 1; xx %= MD; } return mlt; } inline ll gcdex(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll xx, yy; ll gc = gcdex(b, a % b, yy, xx); x = xx; y = yy - (a / b) * xx; return gc; } inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); } inline int64_t hilbertOrder(int x, int y, int pow, int rotate) { if (pow == 0) { return 0; } int hpow = 1 << (pow - 1); int seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2); seg = (seg + rotate) & 3; const int rotateDelta[4] = {3, 0, 0, 1}; int nx = x & (x ^ hpow), ny = y & (y ^ hpow); int nrot = (rotate + rotateDelta[seg]) & 3; int64_t subSquareSize = int64_t(1) << (2 * pow - 2); int64_t ans = seg * subSquareSize; int64_t add = hilbertOrder(nx, ny, pow - 1, nrot); ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1); return ans; } /*-----------------------------------------------------MATH------------------------------------------------*/ void solve() { int n; cin >> n; cin >> s; for (int i = 0; i < 26; i++) { build(1, 0, n - 1, i); } int q; cin >> q; for (int i = 0; i < q; i++) { int kek; cin >> kek; if (kek == 1) { int pos; cin >> pos; char t; cin >> t; update(1, 0, n - 1, pos - 1, t - 'a'); } else { int r; int l; cin >> r >> l; int ans = 0; for (int j = 0; j < 26; j++) { ans += min(get(1, 0, n - 1, r - 1, l - 1, j), 1); } cout << ans << endl; } } } int main() { /*ios::sync_with_stdio(false); cin.tie(nullptr);*/ // freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", // "r", stdin); // freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", // "w", stdout); unsigned int beg_time = clock(); int n = 1; for (int i = 0; i < n; i++) solve(); // unsigned int end_time = clock(); // cout<<endl<<endl<<end_time-beg_time; return 0; }
#pragma GCC optimize("O3", "unroll-loops") // #pragma GCC target("avx2") #include <bits/stdc++.h> #include <stdio.h> using namespace std; #define ull unsigned long long #define si short int #define ll long long #define ld long double #define pb push_back #define pii pair<int, int> #define pil pair<int, ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define piii pair<pair<int, int>, int> #define all(vec) vec.begin(), vec.end() #define piiii pair<pair<int, int>, pair<int, int>> #define fr(a, from, c) for (int a = (from); (a) < (c); (a)++) /*-----------------------------------------------------SegTree---------------------------------------------*/ int mxn11 = (int)(5e5 + 1); vector<vector<int>> t(26, vector<int>(4 * mxn11)); string s; void build(int v, int vl, int vr, int i) { if (vl == vr) { if (s[vl] - 'a' == i) { t[i][v] = 1; } } else { int tmp = (vl + vr) >> 1; build(2 * v, vl, tmp, i); build(2 * v + 1, tmp + 1, vr, i); t[i][v] = t[i][2 * v] + t[i][2 * v + 1]; } } int get(int v, int vl, int vr, int l, int r, int i) { if (l > r) return 0; if (vl == l && vr == r) { return t[i][v]; } int tmp = (vl + vr) >> 1; ll a = get(2 * v, vl, tmp, l, min(tmp, r), i); ll b = get(2 * v + 1, tmp + 1, vr, max(tmp + 1, l), r, i); return a + b; } void update(int v, int vl, int vr, int pos, int what) { if (vl == vr) { for (int i = 0; i < 26; i++) { t[i][v] = (what == i) ? 1 : 0; } return; } int tmp = (vl + vr) >> 1; if (pos <= tmp) update(2 * v, vl, tmp, pos, what); else update(2 * v + 1, tmp + 1, vr, pos, what); for (int i = 0; i < 26; i++) { t[i][v] = t[i][2 * v + 1] + t[i][2 * v]; } } /*-----------------------------------------------------SegTree---------------------------------------------*/ /*-----------------------------------------------------MATH------------------------------------------------*/ inline ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll pwm(ll xx, ll pow, ll MD) { if (pow < 0) { pow = pow % (MD - 1) + MD - 1; } ll mlt = 1; while (pow) { if (pow & 1) { mlt *= xx; mlt %= MD; } xx *= xx; pow >>= 1; xx %= MD; } return mlt; } inline ll gcdex(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll xx, yy; ll gc = gcdex(b, a % b, yy, xx); x = xx; y = yy - (a / b) * xx; return gc; } inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); } inline int64_t hilbertOrder(int x, int y, int pow, int rotate) { if (pow == 0) { return 0; } int hpow = 1 << (pow - 1); int seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2); seg = (seg + rotate) & 3; const int rotateDelta[4] = {3, 0, 0, 1}; int nx = x & (x ^ hpow), ny = y & (y ^ hpow); int nrot = (rotate + rotateDelta[seg]) & 3; int64_t subSquareSize = int64_t(1) << (2 * pow - 2); int64_t ans = seg * subSquareSize; int64_t add = hilbertOrder(nx, ny, pow - 1, nrot); ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1); return ans; } /*-----------------------------------------------------MATH------------------------------------------------*/ void solve() { int n; cin >> n; cin >> s; for (int i = 0; i < 26; i++) { build(1, 0, n - 1, i); } int q; cin >> q; for (int i = 0; i < q; i++) { int kek; cin >> kek; if (kek == 1) { int pos; cin >> pos; char t; cin >> t; update(1, 0, n - 1, pos - 1, t - 'a'); } else { int r; int l; cin >> r >> l; int ans = 0; for (int j = 0; j < 26; j++) { ans += min(get(1, 0, n - 1, r - 1, l - 1, j), 1); } cout << ans << endl; } } } int main() { /*ios::sync_with_stdio(false); cin.tie(nullptr);*/ // freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", // "r", stdin); // freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", // "w", stdout); unsigned int beg_time = clock(); int n = 1; for (int i = 0; i < n; i++) solve(); // unsigned int end_time = clock(); // cout<<endl<<endl<<end_time-beg_time; return 0; }
replace
21
22
21
22
0
p02763
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <typeinfo> #include <unordered_map> #include <utility> #include <vector> using namespace std; using ll = long long; using vll = vector<ll>; using pll = pair<ll, ll>; using qll = queue<ll>; using vb = vector<bool>; using mll = map<ll, ll>; using sll = stack<ll>; #define REP(i, n) for (ll i(0); (i) < (n); (i)++) #define rep(i, n) for (ll i(0); (i) < (n); (i)++) #define ALL(a) a.begin(), a.end() #define enld endl //* missspell check const ll INF = 1LL << 60; const ll sqrtN = 512; //* 512*512=262144 > 10^5 struct RSQ { ll N, K; //* N length of data, K number of buckets string data; vector<vll> bucketSum; //* allocate memory with zeros void init(ll n) { N = n; K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN) // data.assign(K * sqrtN, '0'); data = string(K * sqrtN, '0'); bucketSum.assign(K, vll(26, 0)); } //* constructor RSQ(ll n) { init(n); } //* constructor with init vector data RSQ(ll n, string &a) { init(n); REP(i, n) { data[i] = a[i]; } REP(k, K) { for (ll j = k * sqrtN; j < (k + 1) * sqrtN; j++) { bucketSum[k][data[j] - 'a']++; } } } //* update (add(i, x) -> a[i]+= x) void update(ll i, char x) { ll k = i / sqrtN; //* corresponding bucket char old = data[i]; data[i] = x; bucketSum[k][old - 'a']--; bucketSum[k][data[i] - 'a']++; } //* getSum(s, t)-> return a[s]+a[s+1]+...+a[t-1] //* [x, y) ll getSum(ll x, ll y) { ll cnt = 0; vll tmpChar(26, 0); REP(k, K) { ll l = k * sqrtN, r = (k + 1) * sqrtN; //* bucket [l, r) if (r <= x || y <= l) //* no intersection continue; if (x <= l && r <= y) { //* [l, r) in [x, y) REP(ch, 26) { tmpChar[ch] += bucketSum[k][ch]; } } else { //* has intersection on boundary for (ll i = max(l, x); i < min(r, y); i++) { tmpChar[data[i] - 'a']++; } } } REP(ch, 26) cnt += ((tmpChar[ch] > 0) ? 1 : 0); return cnt; } }; int main() { ll N; cin >> N; string S; cin >> S; RSQ st(N, S); ll Q; cin >> Q; REP(q, Q) { ll type; cin >> type; if (type == 1) { ll i; cin >> i; i--; char c; cin >> c; st.update(i, c); } if (type == 2) { ll l, r; cin >> l >> r; l--; cout << st.getSum(l, r) << endl; } } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <typeinfo> #include <unordered_map> #include <utility> #include <vector> using namespace std; using ll = long long; using vll = vector<ll>; using pll = pair<ll, ll>; using qll = queue<ll>; using vb = vector<bool>; using mll = map<ll, ll>; using sll = stack<ll>; #define REP(i, n) for (ll i(0); (i) < (n); (i)++) #define rep(i, n) for (ll i(0); (i) < (n); (i)++) #define ALL(a) a.begin(), a.end() #define enld endl //* missspell check const ll INF = 1LL << 60; const ll sqrtN = 512; //* 512*512=262144 > 10^5 struct RSQ { ll N, K; //* N length of data, K number of buckets string data; vector<vll> bucketSum; //* allocate memory with zeros void init(ll n) { N = n; K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN) // data.assign(K * sqrtN, '0'); data = string(K * sqrtN, '0'); bucketSum.assign(K, vll(26, 0)); } //* constructor RSQ(ll n) { init(n); } //* constructor with init vector data RSQ(ll n, string &a) { init(n); REP(i, n) { data[i] = a[i]; } REP(k, K) { for (ll j = k * sqrtN; j < min(n, (k + 1) * sqrtN); j++) { bucketSum[k][data[j] - 'a']++; } } } //* update (add(i, x) -> a[i]+= x) void update(ll i, char x) { ll k = i / sqrtN; //* corresponding bucket char old = data[i]; data[i] = x; bucketSum[k][old - 'a']--; bucketSum[k][data[i] - 'a']++; } //* getSum(s, t)-> return a[s]+a[s+1]+...+a[t-1] //* [x, y) ll getSum(ll x, ll y) { ll cnt = 0; vll tmpChar(26, 0); REP(k, K) { ll l = k * sqrtN, r = (k + 1) * sqrtN; //* bucket [l, r) if (r <= x || y <= l) //* no intersection continue; if (x <= l && r <= y) { //* [l, r) in [x, y) REP(ch, 26) { tmpChar[ch] += bucketSum[k][ch]; } } else { //* has intersection on boundary for (ll i = max(l, x); i < min(r, y); i++) { tmpChar[data[i] - 'a']++; } } } REP(ch, 26) cnt += ((tmpChar[ch] > 0) ? 1 : 0); return cnt; } }; int main() { ll N; cin >> N; string S; cin >> S; RSQ st(N, S); ll Q; cin >> Q; REP(q, Q) { ll type; cin >> type; if (type == 1) { ll i; cin >> i; i--; char c; cin >> c; st.update(i, c); } if (type == 2) { ll l, r; cin >> l >> r; l--; cout << st.getSum(l, r) << endl; } } return 0; }
replace
61
62
61
62
0
p02763
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <string> #include <vector> using ll = long long; using namespace std; #include <functional> #include <limits> #define ASSIGN_I \ [](T &ival, T x) { ival = x; } // i番目にxを代入(点更新のデフォルト) template <typename T> class SegmentTree { int n; // 葉の数 T def; // 初期値 && 単位元 vector<T> tree; // 本体 using op_func_t = function<T(T, T)>; using up_func_t = function<void(T &, T)>; op_func_t op_func; // 区間クエリで使う処理 up_func_t up_func; // 点更新で使う処理 // ただの変更の他、i番目にxをたすみたいなこともできる // 区間[a, b)の総和(と言うか総operation(は?)) // ノードk=[l, r)を見ている T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 全く交差しない場合 if (a <= l && r <= b) return tree[(size_t)k]; // 完全に包含される場合 T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2), vr = _query(a, b, k * 2 + 2, (l + r) / 2, r); return op_func(vl, vr); } public: SegmentTree(int _n, T _def, op_func_t _op_func, up_func_t _up_func = ASSIGN_I) : def(_def), op_func(_op_func), up_func(_up_func) { n = 1; while (n < _n) n <<= 1; tree = vector<T>((size_t)(2 * n - 1), def); } // よく使うやつら min, max, sum SegmentTree(int _n, T _def, string mode, up_func_t _up_func = ASSIGN_I) : SegmentTree(_n, _def, mode == "max" ? [](T l, T r) { return max(l, r); } : (mode == "min" ? [](T l, T r) { return min(l, r); } : [](T l, T r) { return l + r; }), // sum _up_func) {} SegmentTree(int _n, string mode, up_func_t _up_func = ASSIGN_I) : SegmentTree(_n, mode == "max" ? numeric_limits<T>::lowest() : (mode == "min" ? numeric_limits<T>::max() : 0), // sum mode, _up_func) {} template <typename ID> void update(ID i, T x) { i += (ID)n - 1; up_func(tree[(size_t)i], x); while (i > 0) { i = (i - 1) / 2; tree[(size_t)i] = op_func(tree[(size_t)(i * 2 + 1)], tree[(size_t)(i * 2 + 2)]); } } template <typename ID1, typename ID2> T query(ID1 a, ID2 b) { return _query((int)a, (int)b, 0, 0, n); } void print_tree() { size_t next = 0, size = (size_t)(2 * n - 1); for (size_t i = 0; i < size; i++) { cout << tree[i]; if (i == next) { cout << '\n'; next = (next + 1) * 2; } else cout << string(size * 2 / (next + 2), ' '); } } auto begin() { return tree.begin() + n - 1; } auto end() { return tree.end(); } T operator[](int i) { return tree[(size_t)(i + n - 1)]; } }; /* コンストラクタ SegmentTree(n, def, op_func, [up_func]) SegmentTree(n, def, mode, [up_func]) SegmentTree(n, mode, [up_func]) */ int main() { int n, q; string s; cin >> n >> s >> q; vector<SegmentTree<int>> vsg(26, SegmentTree<int>(n, "sum")); for (int i = 0; i < n; i++) { vsg[s[i] - 'a'].update(i, 1); } for (int i = 0, t; i < q; i++) { cin >> t; if (t == 1) { int id; char c; cin >> id >> c; id--; vsg[s[id] - 'a'].update(i, 0); vsg[c - 'a'].update(i, 1); s[id] = c; } else { int l, r; cin >> l >> r; l--; int cnt = 0; for (auto &vi : vsg) { if (vi.query(l, r)) cnt++; } cout << cnt << '\n'; } } return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <string> #include <vector> using ll = long long; using namespace std; #include <functional> #include <limits> #define ASSIGN_I \ [](T &ival, T x) { ival = x; } // i番目にxを代入(点更新のデフォルト) template <typename T> class SegmentTree { int n; // 葉の数 T def; // 初期値 && 単位元 vector<T> tree; // 本体 using op_func_t = function<T(T, T)>; using up_func_t = function<void(T &, T)>; op_func_t op_func; // 区間クエリで使う処理 up_func_t up_func; // 点更新で使う処理 // ただの変更の他、i番目にxをたすみたいなこともできる // 区間[a, b)の総和(と言うか総operation(は?)) // ノードk=[l, r)を見ている T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 全く交差しない場合 if (a <= l && r <= b) return tree[(size_t)k]; // 完全に包含される場合 T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2), vr = _query(a, b, k * 2 + 2, (l + r) / 2, r); return op_func(vl, vr); } public: SegmentTree(int _n, T _def, op_func_t _op_func, up_func_t _up_func = ASSIGN_I) : def(_def), op_func(_op_func), up_func(_up_func) { n = 1; while (n < _n) n <<= 1; tree = vector<T>((size_t)(2 * n - 1), def); } // よく使うやつら min, max, sum SegmentTree(int _n, T _def, string mode, up_func_t _up_func = ASSIGN_I) : SegmentTree(_n, _def, mode == "max" ? [](T l, T r) { return max(l, r); } : (mode == "min" ? [](T l, T r) { return min(l, r); } : [](T l, T r) { return l + r; }), // sum _up_func) {} SegmentTree(int _n, string mode, up_func_t _up_func = ASSIGN_I) : SegmentTree(_n, mode == "max" ? numeric_limits<T>::lowest() : (mode == "min" ? numeric_limits<T>::max() : 0), // sum mode, _up_func) {} template <typename ID> void update(ID i, T x) { i += (ID)n - 1; up_func(tree[(size_t)i], x); while (i > 0) { i = (i - 1) / 2; tree[(size_t)i] = op_func(tree[(size_t)(i * 2 + 1)], tree[(size_t)(i * 2 + 2)]); } } template <typename ID1, typename ID2> T query(ID1 a, ID2 b) { return _query((int)a, (int)b, 0, 0, n); } void print_tree() { size_t next = 0, size = (size_t)(2 * n - 1); for (size_t i = 0; i < size; i++) { cout << tree[i]; if (i == next) { cout << '\n'; next = (next + 1) * 2; } else cout << string(size * 2 / (next + 2), ' '); } } auto begin() { return tree.begin() + n - 1; } auto end() { return tree.end(); } T operator[](int i) { return tree[(size_t)(i + n - 1)]; } }; /* コンストラクタ SegmentTree(n, def, op_func, [up_func]) SegmentTree(n, def, mode, [up_func]) SegmentTree(n, mode, [up_func]) */ int main() { int n, q; string s; cin >> n >> s >> q; vector<SegmentTree<int>> vsg(26, SegmentTree<int>(n, "sum")); for (int i = 0; i < n; i++) { vsg[s[i] - 'a'].update(i, 1); } for (int i = 0, t; i < q; i++) { cin >> t; if (t == 1) { int id; char c; cin >> id >> c; id--; vsg[s[id] - 'a'].update(id, 0); vsg[c - 'a'].update(id, 1); s[id] = c; } else { int l, r; cin >> l >> r; l--; int cnt = 0; for (auto &vi : vsg) { if (vi.query(l, r)) cnt++; } cout << cnt << '\n'; } } return 0; }
replace
119
121
119
121
0
p02763
C++
Time Limit Exceeded
#include <iostream> #include <set> #include <string> using namespace std; int main(void) { int n, q; string s; cin >> n >> s >> q; set<int> st[26]; for (int i = 0; i < n; i++) { st[s[i] - 'a'].insert(i + 1); } for (int i = 0; i < q; i++) { int t; cin >> t; if (t == 1) { int p; char c; cin >> p >> c; st[s[p - 1] - 'a'].erase(p); s[p - 1] = c; st[c - 'a'].insert(p); } else { int l, r; cin >> l >> r; int ans = 0; for (int i = 0; i < 26; i++) { auto it = lower_bound(st[i].begin(), st[i].end(), l); if (it != st[i].end() && *it <= r) { ans++; } } printf("%d\n", ans); } } return 0; }
#include <iostream> #include <set> #include <string> using namespace std; int main(void) { int n, q; string s; cin >> n >> s >> q; set<int> st[26]; for (int i = 0; i < n; i++) { st[s[i] - 'a'].insert(i + 1); } for (int i = 0; i < q; i++) { int t; cin >> t; if (t == 1) { int p; char c; cin >> p >> c; st[s[p - 1] - 'a'].erase(p); s[p - 1] = c; st[c - 'a'].insert(p); } else { int l, r; cin >> l >> r; int ans = 0; for (int i = 0; i < 26; i++) { auto it = st[i].lower_bound(l); if (it != st[i].end() && *it <= r) { ans++; } } printf("%d\n", ans); } } return 0; }
replace
33
34
33
34
TLE
p02763
C++
Time Limit Exceeded
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using int64 = long long; const int mod = 1e9 + 7; const int64 infll = (1LL << 58) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename T = int64> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename F> struct FixPoint : F { FixPoint(F &&f) : F(forward<F>(f)) {} template <typename... Args> decltype(auto) operator()(Args &&...args) const { return F::operator()(*this, forward<Args>(args)...); } }; template <typename F> inline decltype(auto) MFP(F &&f) { return FixPoint<F>{forward<F>(f)}; } int main() { int N, Q; string S; cin >> N >> S >> Q; int bit[500000] = {}; for (int i = 0; i < N; i++) { bit[i] = S[i] - 'a'; bit[i] = 1 << bit[i]; } for (int i = 0; i < Q; i++) { int t; cin >> t; if (t == 1) { int k; char c; cin >> k >> c; --k; bit[k] = c - 'a'; bit[k] = 1 << bit[k]; } else { int l, r; cin >> l >> r; --l; int tap = 0; for (int k = l; k < r; k++) tap |= bit[k]; cout << __builtin_popcount(tap) << endl; } } }
#include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; using int64 = long long; const int mod = 1e9 + 7; const int64 infll = (1LL << 58) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename T = int64> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename F> struct FixPoint : F { FixPoint(F &&f) : F(forward<F>(f)) {} template <typename... Args> decltype(auto) operator()(Args &&...args) const { return F::operator()(*this, forward<Args>(args)...); } }; template <typename F> inline decltype(auto) MFP(F &&f) { return FixPoint<F>{forward<F>(f)}; } int main() { int N, Q; string S; cin >> N >> S >> Q; int bit[500000] = {}; for (int i = 0; i < N; i++) { bit[i] = S[i] - 'a'; bit[i] = 1 << bit[i]; } for (int i = 0; i < Q; i++) { int t; cin >> t; if (t == 1) { int k; char c; cin >> k >> c; --k; bit[k] = c - 'a'; bit[k] = 1 << bit[k]; } else { int l, r; cin >> l >> r; --l; int tap = 0; for (int k = l; k < r; k++) tap |= bit[k]; cout << __builtin_popcount(tap) << endl; } } }
replace
0
2
0
5
TLE
p02763
C++
Time Limit Exceeded
/* lib.cpp */ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define DEBUG(x) cout << #x << " = " << (x) << ","; using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using graph = vector<vector<int>>; const ll MOD = 1e9 + 7; const ld EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int edx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int edy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template <class T> void chmin(T &a, T b) { a = min(a, b); } template <class T> void chmax(T &a, T b) { a = max(a, b); } ll modpow(ll a, ll b, ll p = MOD) { ll ret = 1; while (b != 0) { if ((b & 1) == 1) ret *= a; a *= a; if (a >= p) a %= p; if (ret >= p) ret %= p; b >>= 1; } return ret; } int digit(ll x, ll base = 10) { int ret = 0; while (x) { x /= base; ret++; } return ret; } int sumOfDigit(ll x, ll base = 10) { int ret = 0; while (x) { ret += x % base; x /= base; } return ret; } ll factrial(int n) { ll ret = 1; for (int i = 1; i <= n; i++) { ret *= i; } return ret; } ll gcd(ll a, ll b) { while (b != 0) { a %= b; swap(a, b); } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll modinv(ll a, ll p = MOD) { ll b = p, u = 1, v = 0; while (b) { ll tmp = a / b; a -= tmp * b; u -= tmp * v; swap(a, b); swap(u, v); } u %= p; if (u < 0) u += p; return u; } bool isprime(ll p) { if (p <= 1) return false; ll s = min(p - 1, (ll)ceil(sqrt(p))); for (int i = 2; i <= s; i++) if (p % i == 0) return false; return true; } ll minDivisor(ll x, ll n = 2) { if (x <= 1) return 1; ll s = min(x - 1, (ll)ceil(sqrt(x))); for (int i = n; i <= s; i++) if (x % i == 0) return i; return x; } ll countDivisor(ll x) { map<ll, int> m; if (x <= 1) return 1; ll s = min(x - 1, (ll)ceil(sqrt(x))); for (int i = 2; i <= s; i++) { if (x % i == 0) { x /= i; m[i]++; i = 1; } } if (x != 1) m[x]++; ll ret = 1; for (auto i : m) { ret *= i.second + 1; } return ret; } class disjoint_set { vector<int> _parent, _size; public: disjoint_set(int n) : _parent(n), _size(n) { for (int i = 0; i < n; i++) { _parent[i] = i; _size[i] = 1; } } int root(int x) { if (_parent[x] == x) return x; return _parent[x] = root(_parent[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; _parent[rx] = ry; _size[ry] += _size[rx]; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return _size[root(x)]; } }; void init() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); } void solve() { int N, Q; string S; cin >> N; cin >> S; cin >> Q; set<int> s[26]; for (int i = 0; i < 26; i++) { s[i] = {}; } vector<int> ch(N); for (int i = 0; i < N; i++) { ch[i] = S[i] - 'a'; s[ch[i]].insert(i); } for (int i = 0; i < Q; i++) { int q; cin >> q; if (q == 1) { int iq; char cq; cin >> iq >> cq; iq--; s[ch[iq]].erase(iq); ch[iq] = cq - 'a'; s[cq - 'a'].insert(iq); } else { int l, r, cnt = 0; cin >> l >> r; l--; r--; for (int j = 0; j < 26; j++) { auto it = lower_bound(s[j].begin(), s[j].end(), l); if (it != s[j].end() && *it <= r) { cnt++; } } cout << cnt << endl; } } } int main() { init(); solve(); return 0; }
/* lib.cpp */ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define DEBUG(x) cout << #x << " = " << (x) << ","; using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using graph = vector<vector<int>>; const ll MOD = 1e9 + 7; const ld EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int edx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int edy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template <class T> void chmin(T &a, T b) { a = min(a, b); } template <class T> void chmax(T &a, T b) { a = max(a, b); } ll modpow(ll a, ll b, ll p = MOD) { ll ret = 1; while (b != 0) { if ((b & 1) == 1) ret *= a; a *= a; if (a >= p) a %= p; if (ret >= p) ret %= p; b >>= 1; } return ret; } int digit(ll x, ll base = 10) { int ret = 0; while (x) { x /= base; ret++; } return ret; } int sumOfDigit(ll x, ll base = 10) { int ret = 0; while (x) { ret += x % base; x /= base; } return ret; } ll factrial(int n) { ll ret = 1; for (int i = 1; i <= n; i++) { ret *= i; } return ret; } ll gcd(ll a, ll b) { while (b != 0) { a %= b; swap(a, b); } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll modinv(ll a, ll p = MOD) { ll b = p, u = 1, v = 0; while (b) { ll tmp = a / b; a -= tmp * b; u -= tmp * v; swap(a, b); swap(u, v); } u %= p; if (u < 0) u += p; return u; } bool isprime(ll p) { if (p <= 1) return false; ll s = min(p - 1, (ll)ceil(sqrt(p))); for (int i = 2; i <= s; i++) if (p % i == 0) return false; return true; } ll minDivisor(ll x, ll n = 2) { if (x <= 1) return 1; ll s = min(x - 1, (ll)ceil(sqrt(x))); for (int i = n; i <= s; i++) if (x % i == 0) return i; return x; } ll countDivisor(ll x) { map<ll, int> m; if (x <= 1) return 1; ll s = min(x - 1, (ll)ceil(sqrt(x))); for (int i = 2; i <= s; i++) { if (x % i == 0) { x /= i; m[i]++; i = 1; } } if (x != 1) m[x]++; ll ret = 1; for (auto i : m) { ret *= i.second + 1; } return ret; } class disjoint_set { vector<int> _parent, _size; public: disjoint_set(int n) : _parent(n), _size(n) { for (int i = 0; i < n; i++) { _parent[i] = i; _size[i] = 1; } } int root(int x) { if (_parent[x] == x) return x; return _parent[x] = root(_parent[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; _parent[rx] = ry; _size[ry] += _size[rx]; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return _size[root(x)]; } }; void init() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); } void solve() { int N, Q; string S; cin >> N; cin >> S; cin >> Q; set<int> s[26]; for (int i = 0; i < 26; i++) { s[i] = {}; } vector<int> ch(N); for (int i = 0; i < N; i++) { ch[i] = S[i] - 'a'; s[ch[i]].insert(i); } for (int i = 0; i < Q; i++) { int q; cin >> q; if (q == 1) { int iq; char cq; cin >> iq >> cq; iq--; s[ch[iq]].erase(iq); ch[iq] = cq - 'a'; s[cq - 'a'].insert(iq); } else { int l, r, cnt = 0; cin >> l >> r; l--; r--; for (int j = 0; j < 26; j++) { auto it = s[j].lower_bound(l); if (it != s[j].end() && *it <= r) { cnt++; } } cout << cnt << endl; } } } int main() { init(); solve(); return 0; }
replace
210
211
210
211
TLE
p02763
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; int q; cin >> q; set<int> pos[26]; for (int i = 0; i < n; i++) { pos[s[i] - 'a'].insert(i); } while (q-- > 0) { int type; cin >> type; if (type == 1) { int i; char c; cin >> i >> c; i--; pos[s[i]].erase(i); pos[c - 'a'].insert(i); s[i] = c; } if (type == 2) { int l, r; cin >> l >> r; l--; r--; int kind = 0; for (int i = 0; i < 26; i++) { set<int>::iterator it = pos[i].lower_bound(l); set<int>::iterator last = pos[i].upper_bound(n); if (it != last && *it <= r) { kind++; } } cout << kind << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; int q; cin >> q; set<int> pos[26]; for (int i = 0; i < n; i++) { pos[s[i] - 'a'].insert(i); } while (q-- > 0) { int type; cin >> type; if (type == 1) { int i; char c; cin >> i >> c; i--; pos[s[i] - 'a'].erase(i); pos[c - 'a'].insert(i); s[i] = c; } if (type == 2) { int l, r; cin >> l >> r; l--; r--; int kind = 0; for (int i = 0; i < 26; i++) { set<int>::iterator it = pos[i].lower_bound(l); set<int>::iterator last = pos[i].upper_bound(n); if (it != last && *it <= r) { kind++; } } cout << kind << endl; } } return 0; }
replace
24
25
24
25
0
p02763
C++
Memory Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll N, S, Q; ll q[500001]; map<char, int>::iterator ite; ll A[500001][20][26]; int B[500001]; int ans[26]; int henkan(char s) { if (s == 'a') return 0; if (s == 'b') return 1; if (s == 'c') return 2; if (s == 'd') return 3; if (s == 'e') return 4; if (s == 'f') return 5; if (s == 'g') return 6; if (s == 'h') return 7; if (s == 'i') return 8; if (s == 'j') return 9; if (s == 'k') return 10; if (s == 'l') return 11; if (s == 'm') return 12; if (s == 'n') return 13; if (s == 'o') return 14; if (s == 'p') return 15; if (s == 'q') return 16; if (s == 'r') return 17; if (s == 's') return 18; if (s == 't') return 19; if (s == 'u') return 20; if (s == 'v') return 21; if (s == 'w') return 22; if (s == 'x') return 23; if (s == 'y') return 24; if (s == 'z') return 25; else return 0; } int main() { cin >> N; int NN = N; for (int i = 0; i < N; i++) { char s; cin >> s; int a = henkan(s); A[i][0][a] = 1; B[i] = a; } int h = 1; N /= 2; while (N > 0) { for (int i = 0; i < N; i++) { for (int k = 0; k < 26; k++) { A[i][h][k] = A[2 * i][h - 1][k] + A[2 * i + 1][h - 1][k]; } } N /= 2; h++; } cin >> Q; for (int i = 0; i < Q; i++) { int a; cin >> a; if (a == 1) { int b; char c; cin >> b >> c; int d = henkan(c); int e = B[b - 1]; B[b - 1] = d; int bb = b; int j = 0; int NNN = NN; while (bb <= NNN) { A[bb - 1][j][e] -= 1; A[bb - 1][j][d] += 1; bb = (bb + 1) / 2; NNN /= 2; j++; } } else { int b, c; cin >> b >> c; int k = 0; while (c > 0) { if (c % 2 == 1) { for (int j = 0; j < 26; j++) { ans[j] += A[c - 1][k][j]; } } k++; c /= 2; } k = 0; b = b - 1; while (b > 0) { if (b % 2 == 1) { for (int j = 0; j < 26; j++) { ans[j] -= A[b - 1][k][j]; } } k++; b /= 2; } int kai = 0; for (int j = 0; j < 26; j++) { if (ans[j] != 0) { kai++; ans[j] = 0; } } cout << kai << endl; } } }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; int N, S, Q; int A[500001][20][26]; int B[500001]; int ans[26]; int henkan(char s) { if (s == 'a') return 0; if (s == 'b') return 1; if (s == 'c') return 2; if (s == 'd') return 3; if (s == 'e') return 4; if (s == 'f') return 5; if (s == 'g') return 6; if (s == 'h') return 7; if (s == 'i') return 8; if (s == 'j') return 9; if (s == 'k') return 10; if (s == 'l') return 11; if (s == 'm') return 12; if (s == 'n') return 13; if (s == 'o') return 14; if (s == 'p') return 15; if (s == 'q') return 16; if (s == 'r') return 17; if (s == 's') return 18; if (s == 't') return 19; if (s == 'u') return 20; if (s == 'v') return 21; if (s == 'w') return 22; if (s == 'x') return 23; if (s == 'y') return 24; if (s == 'z') return 25; else return 0; } int main() { cin >> N; int NN = N; for (int i = 0; i < N; i++) { char s; cin >> s; int a = henkan(s); A[i][0][a] = 1; B[i] = a; } int h = 1; N /= 2; while (N > 0) { for (int i = 0; i < N; i++) { for (int k = 0; k < 26; k++) { A[i][h][k] = A[2 * i][h - 1][k] + A[2 * i + 1][h - 1][k]; } } N /= 2; h++; } cin >> Q; for (int i = 0; i < Q; i++) { int a; cin >> a; if (a == 1) { int b; char c; cin >> b >> c; int d = henkan(c); int e = B[b - 1]; B[b - 1] = d; int bb = b; int j = 0; int NNN = NN; while (bb <= NNN) { A[bb - 1][j][e] -= 1; A[bb - 1][j][d] += 1; bb = (bb + 1) / 2; NNN /= 2; j++; } } else { int b, c; cin >> b >> c; int k = 0; while (c > 0) { if (c % 2 == 1) { for (int j = 0; j < 26; j++) { ans[j] += A[c - 1][k][j]; } } k++; c /= 2; } k = 0; b = b - 1; while (b > 0) { if (b % 2 == 1) { for (int j = 0; j < 26; j++) { ans[j] -= A[b - 1][k][j]; } } k++; b /= 2; } int kai = 0; for (int j = 0; j < 26; j++) { if (ans[j] != 0) { kai++; ans[j] = 0; } } cout << kai << endl; } } }
replace
10
14
10
12
MLE
p02763
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 1000000007 #define ll long long #define F first #define S second #define pii pair<ll int, ll int> #define pb push_back #define ppb pop_back #define vi vector<ll int> int seg[2000000][26]; int input[500001][26]; void construct_tree(int low, int high, int pos) { if (low == high) { for (int i = 0; i < 26; i++) seg[pos][i] = input[low][i]; return; } int mid = (low + high) / 2; construct_tree(low, mid, 2 * pos + 1); construct_tree(mid + 1, high, 2 * pos + 2); for (int i = 0; i < 26; i++) seg[pos][i] = seg[2 * pos + 1][i] + seg[2 * pos + 2][i]; } int range_query(int qlow, int qhigh, int low, int high, int pos, int c) { if (qhigh < low || high < qlow) return 0; if (qlow <= low && high <= qhigh) return seg[pos][c]; int mid = (low + high) / 2; return range_query(qlow, qhigh, low, mid, 2 * pos + 1, c) + range_query(qlow, qhigh, mid + 1, high, 2 * pos + 2, c); } void range_update(int uindex, int low, int high, int pos) { if (uindex < low || high < uindex) return; if (low == uindex && high == uindex) { for (int i = 0; i < 26; i++) { seg[pos][i] = input[uindex][i]; } // seg[pos][c] = input[uindex][c]; // seg[pos][temp] = input[uindex][temp]; return; } int mid = (low + high) / 2; range_update(uindex, low, mid, 2 * pos + 1); range_update(uindex, mid + 1, high, 2 * pos + 2); for (int i = 0; i < 26; i++) { seg[pos][i] = seg[2 * pos + 1][i] + seg[2 * pos + 2][i]; } // seg[pos][c] = seg[2*pos+1][c] + seg[2*pos+2][c]; // seg[pos][temp] = seg[2*pos+1][temp] + seg[2*pos+2][temp]; } int main() { ifstream cin("01-handmade-00"); ofstream cout("out"); ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { int n; cin >> n; string str; cin >> str; for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) input[i][j] = 0; input[i][str[i] - 'a'] = 1; } for (int i = 0; i < 2000000; i++) for (int j = 0; j < 26; j++) { seg[i][j] = 0; } construct_tree(0, n - 1, 0); // for(int i=0;i<15;i++){ // cout << i << "---"; // for(int j=0;j<26;j++) cout << seg[i][j] << " "; // cout << endl; // } int q; cin >> q; int op, l, r; while (q--) { cin >> op >> l; if (op == 1) { char c; cin >> c; for (int i = 0; i < 26; i++) input[l - 1][i] = 0; // int temp = str[l-1] - 'a'; // str[l-1] = c; // input[l-1][temp] = 0; input[l - 1][c - 'a'] = 1; range_update(l - 1, 0, n - 1, 0); // for(int i=0;i<15;i++){ // cout << i << "---"; // for(int j=0;j<26;j++) cout << seg[i][j] << " "; // cout << endl; // } } else { cin >> r; int ans = 0; for (int i = 0; i < 26; i++) { if (range_query(l - 1, r - 1, 0, n - 1, 0, i) > 0) ans++; } cout << ans << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000007 #define ll long long #define F first #define S second #define pii pair<ll int, ll int> #define pb push_back #define ppb pop_back #define vi vector<ll int> int seg[2000000][26]; int input[500001][26]; void construct_tree(int low, int high, int pos) { if (low == high) { for (int i = 0; i < 26; i++) seg[pos][i] = input[low][i]; return; } int mid = (low + high) / 2; construct_tree(low, mid, 2 * pos + 1); construct_tree(mid + 1, high, 2 * pos + 2); for (int i = 0; i < 26; i++) seg[pos][i] = seg[2 * pos + 1][i] + seg[2 * pos + 2][i]; } int range_query(int qlow, int qhigh, int low, int high, int pos, int c) { if (qhigh < low || high < qlow) return 0; if (qlow <= low && high <= qhigh) return seg[pos][c]; int mid = (low + high) / 2; return range_query(qlow, qhigh, low, mid, 2 * pos + 1, c) + range_query(qlow, qhigh, mid + 1, high, 2 * pos + 2, c); } void range_update(int uindex, int low, int high, int pos) { if (uindex < low || high < uindex) return; if (low == uindex && high == uindex) { for (int i = 0; i < 26; i++) { seg[pos][i] = input[uindex][i]; } // seg[pos][c] = input[uindex][c]; // seg[pos][temp] = input[uindex][temp]; return; } int mid = (low + high) / 2; range_update(uindex, low, mid, 2 * pos + 1); range_update(uindex, mid + 1, high, 2 * pos + 2); for (int i = 0; i < 26; i++) { seg[pos][i] = seg[2 * pos + 1][i] + seg[2 * pos + 2][i]; } // seg[pos][c] = seg[2*pos+1][c] + seg[2*pos+2][c]; // seg[pos][temp] = seg[2*pos+1][temp] + seg[2*pos+2][temp]; } int main() { // ifstream cin("01-handmade-00"); // ofstream cout("out"); ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { int n; cin >> n; string str; cin >> str; for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) input[i][j] = 0; input[i][str[i] - 'a'] = 1; } for (int i = 0; i < 2000000; i++) for (int j = 0; j < 26; j++) { seg[i][j] = 0; } construct_tree(0, n - 1, 0); // for(int i=0;i<15;i++){ // cout << i << "---"; // for(int j=0;j<26;j++) cout << seg[i][j] << " "; // cout << endl; // } int q; cin >> q; int op, l, r; while (q--) { cin >> op >> l; if (op == 1) { char c; cin >> c; for (int i = 0; i < 26; i++) input[l - 1][i] = 0; // int temp = str[l-1] - 'a'; // str[l-1] = c; // input[l-1][temp] = 0; input[l - 1][c - 'a'] = 1; range_update(l - 1, 0, n - 1, 0); // for(int i=0;i<15;i++){ // cout << i << "---"; // for(int j=0;j<26;j++) cout << seg[i][j] << " "; // cout << endl; // } } else { cin >> r; int ans = 0; for (int i = 0; i < 26; i++) { if (range_query(l - 1, r - 1, 0, n - 1, 0, i) > 0) ans++; } cout << ans << endl; } } } return 0; }
replace
61
63
61
63
-11
p02763
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; typedef long long ll; void solve() { ll n, q; string s; cin >> n >> s >> q; vector<set<ll>> st(26); for (int i = 0; i < n; i++) { int x = s[i] - 'a'; st[x].insert(i); } cout << endl; for (int i = 0; i < q; i++) { int x; cin >> x; if (x == 1) { int y; char c1, c2; cin >> y >> c2; c1 = s[y - 1]; st[c1 - 'a'].erase(y - 1); st[c2 - 'a'].insert(y - 1); s[y - 1] = c2; } else { int l, r, sum = 0; cin >> l >> r; for (int j = 0; j < 26; j++) { if (lower_bound(st[j].begin(), st[j].end(), l - 1) != st[j].end()) { int y = *lower_bound(st[j].begin(), st[j].end(), l - 1); if (y <= r - 1) sum++; } } cout << sum << endl; } } return; } int main() { solve(); return 0; }
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; typedef long long ll; void solve() { ll n, q; string s; cin >> n >> s >> q; vector<set<ll>> st(26); for (int i = 0; i < n; i++) { int x = s[i] - 'a'; st[x].insert(i); } cout << endl; for (int i = 0; i < q; i++) { int x; cin >> x; if (x == 1) { int y; char c1, c2; cin >> y >> c2; c1 = s[y - 1]; st[c1 - 'a'].erase(y - 1); st[c2 - 'a'].insert(y - 1); s[y - 1] = c2; } else { int l, r, sum = 0; cin >> l >> r; for (int j = 0; j < 26; j++) { if (st[j].lower_bound(l - 1) != st[j].end()) { int y = *(st[j].lower_bound(l - 1)); if (y <= r - 1) sum++; } } cout << sum << endl; } } return; } int main() { solve(); return 0; }
replace
32
34
32
34
TLE
p02763
C++
Runtime Error
// #define _GLIBCXX_DEBUG // #include <atcoder/all> #include <bits/stdc++.h> #ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP #define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1 #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int128 = typename std::conditional<std::is_same<T, __uint128_t>::value || std::is_same<T, unsigned __int128>::value, std::true_type, std::false_type>::type; template <class T> using make_unsigned_int128 = typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>; template <class T> using is_integral = typename std::conditional<std::is_integral<T>::value || is_signed_int128<T>::value || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_signed_int = typename std::conditional<(is_integral<T>::value && std::is_signed<T>::value) || is_signed_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<(is_integral<T>::value && std::is_unsigned<T>::value) || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional< is_signed_int128<T>::value, make_unsigned_int128<T>, typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>, std::common_type<T>>::type>::type; #else template <class T> using is_integral = typename std::is_integral<T>; template <class T> using is_signed_int = typename std::conditional<is_integral<T>::value && std::is_signed<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<is_integral<T>::value && std::is_unsigned<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>, std::common_type<T>>::type; #endif template <class T> using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>; template <class T> using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>; template <class T> using to_unsigned_t = typename to_unsigned<T>::type; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_TYPE_TRAITS_HPP #ifndef ATCODER_FENWICKTREE_HPP #define ATCODER_FENWICKTREE_HPP 1 #include <cassert> #include <vector> namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree template <class T> struct fenwick_tree { using U = internal::to_unsigned_t<T>; public: fenwick_tree() : _n(0) {} fenwick_tree(int n) : _n(n), data(n) {} void add(int p, T x) { assert(0 <= p && p < _n); p++; while (p <= _n) { data[p - 1] += U(x); p += p & -p; } } T sum(int l, int r) { assert(0 <= l && l <= r && r <= _n); return sum(r) - sum(l); } private: int _n; std::vector<U> data; U sum(int r) { U s = 0; while (r > 0) { s += data[r - 1]; r -= r & -r; } return s; } }; } // namespace atcoder #endif // ATCODER_FENWICKTREE_HPP using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MOD = 1000000007; // const ll MOD=998244353; const long long INF = 1LL << 60; const double pi = acos(-1.0); int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << fixed << setprecision(15); ll N, Q; cin >> N; string S; cin >> S; cin >> Q; vector<fenwick_tree<int>> fw_vec(26, fenwick_tree<int>(N)); rep(i, N) { ll c = S[i] - 'a'; fw_vec[c].add(i, 1); } rep(i, Q) { int t; cin >> t; if (t == 1) { ll j; char chnc; cin >> j >> chnc; j--; ll c = S[i] - 'a'; S[i] = chnc; ll nc = chnc - 'a'; fw_vec[c].add(j, -1); fw_vec[nc].add(j, 1); } else { ll l, r; cin >> l >> r; l--; r--; ll ans = 0; rep(j, 26) { if (fw_vec[j].sum(l, r + 1)) ans++; } cout << ans << '\n'; } } return 0; }
// #define _GLIBCXX_DEBUG // #include <atcoder/all> #include <bits/stdc++.h> #ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP #define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1 #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int128 = typename std::conditional<std::is_same<T, __uint128_t>::value || std::is_same<T, unsigned __int128>::value, std::true_type, std::false_type>::type; template <class T> using make_unsigned_int128 = typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>; template <class T> using is_integral = typename std::conditional<std::is_integral<T>::value || is_signed_int128<T>::value || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_signed_int = typename std::conditional<(is_integral<T>::value && std::is_signed<T>::value) || is_signed_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<(is_integral<T>::value && std::is_unsigned<T>::value) || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional< is_signed_int128<T>::value, make_unsigned_int128<T>, typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>, std::common_type<T>>::type>::type; #else template <class T> using is_integral = typename std::is_integral<T>; template <class T> using is_signed_int = typename std::conditional<is_integral<T>::value && std::is_signed<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<is_integral<T>::value && std::is_unsigned<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>, std::common_type<T>>::type; #endif template <class T> using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>; template <class T> using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>; template <class T> using to_unsigned_t = typename to_unsigned<T>::type; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_TYPE_TRAITS_HPP #ifndef ATCODER_FENWICKTREE_HPP #define ATCODER_FENWICKTREE_HPP 1 #include <cassert> #include <vector> namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree template <class T> struct fenwick_tree { using U = internal::to_unsigned_t<T>; public: fenwick_tree() : _n(0) {} fenwick_tree(int n) : _n(n), data(n) {} void add(int p, T x) { assert(0 <= p && p < _n); p++; while (p <= _n) { data[p - 1] += U(x); p += p & -p; } } T sum(int l, int r) { assert(0 <= l && l <= r && r <= _n); return sum(r) - sum(l); } private: int _n; std::vector<U> data; U sum(int r) { U s = 0; while (r > 0) { s += data[r - 1]; r -= r & -r; } return s; } }; } // namespace atcoder #endif // ATCODER_FENWICKTREE_HPP using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MOD = 1000000007; // const ll MOD=998244353; const long long INF = 1LL << 60; const double pi = acos(-1.0); int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << fixed << setprecision(15); ll N, Q; cin >> N; string S; cin >> S; cin >> Q; vector<fenwick_tree<int>> fw_vec(26, fenwick_tree<int>(N)); rep(i, N) { ll c = S[i] - 'a'; fw_vec[c].add(i, 1); } rep(i, Q) { int t; cin >> t; if (t == 1) { ll j; char chnc; cin >> j >> chnc; j--; ll c = S[j] - 'a'; S[j] = chnc; ll nc = chnc - 'a'; fw_vec[c].add(j, -1); fw_vec[nc].add(j, 1); } else { ll l, r; cin >> l >> r; l--; r--; ll ans = 0; rep(j, 26) { if (fw_vec[j].sum(l, r + 1)) ans++; } cout << ans << '\n'; } } return 0; }
replace
194
196
194
196
0
p02763
C++
Runtime Error
/*input abcdefgh 4 1 2 a 1 8 g 2 1 3 2 1 8 */ /* ______________ | ) | ) / |______/ | | \ | | ) \ |_____|_______) */ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef long double ld; #define pb push_back #define all(c) c.begin(), c.end() #define allr(c) c.rbegin(), c.rend() int mod = 1000000007; const int inf = 1034567891; const ll LL_INF = 1234567890123456789ll; #define PI 3.14159265 #define endl '\n' #define F first #define S second #define debug(x) cout << #x << " = " << x << endl; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define out(container) \ for (auto it : container) \ cout << it << " "; \ cout << endl; template <typename T> T GCD(T a, T b) { ll t; while (a) { t = a; a = b % a; b = t; } return b; } template <typename T> string toString(T a) { return to_string(a); } template <typename T> void toInt(string s, T &x) { stringstream str(s); str >> x; } inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mul(int x, int y) { return (x * 1ll * y) % mod; } inline int powr(int a, ll b) { int x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; } return x; } inline int inv(int a) { return powr(a, mod - 2); } const int N = 1e5 + 5; int bit[26][N]; void update(int w, int ind, int val) { for (; ind < N; ind += (ind & -ind)) { bit[w][ind] += val; } } int query(int w, int ind) { int ans = 0; for (; ind > 0; ind -= (ind & -ind)) { ans += bit[w][ind]; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int ghj; cin >> ghj; string str; cin >> str; int n = str.size(); str = '#' + str; for (int i = 1; i <= n; i++) { update(str[i] - 'a', i, 1); } int q; cin >> q; while (q--) { int type; cin >> type; if (type == 1) { int ind; char c; cin >> ind >> c; int w = c - 'a'; update(str[ind] - 'a', ind, -1); update(w, ind, 1); str[ind] = c; } else { int l, r; cin >> l >> r; int ans = 0; for (int i = 0; i < 26; i++) { int c = query(i, r) - query(i, l - 1); ans += (c >= 1); } cout << ans << endl; } } return 0; }
/*input abcdefgh 4 1 2 a 1 8 g 2 1 3 2 1 8 */ /* ______________ | ) | ) / |______/ | | \ | | ) \ |_____|_______) */ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef long double ld; #define pb push_back #define all(c) c.begin(), c.end() #define allr(c) c.rbegin(), c.rend() int mod = 1000000007; const int inf = 1034567891; const ll LL_INF = 1234567890123456789ll; #define PI 3.14159265 #define endl '\n' #define F first #define S second #define debug(x) cout << #x << " = " << x << endl; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define out(container) \ for (auto it : container) \ cout << it << " "; \ cout << endl; template <typename T> T GCD(T a, T b) { ll t; while (a) { t = a; a = b % a; b = t; } return b; } template <typename T> string toString(T a) { return to_string(a); } template <typename T> void toInt(string s, T &x) { stringstream str(s); str >> x; } inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mul(int x, int y) { return (x * 1ll * y) % mod; } inline int powr(int a, ll b) { int x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; } return x; } inline int inv(int a) { return powr(a, mod - 2); } const int N = 7e5 + 5; int bit[26][N]; void update(int w, int ind, int val) { for (; ind < N; ind += (ind & -ind)) { bit[w][ind] += val; } } int query(int w, int ind) { int ans = 0; for (; ind > 0; ind -= (ind & -ind)) { ans += bit[w][ind]; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int ghj; cin >> ghj; string str; cin >> str; int n = str.size(); str = '#' + str; for (int i = 1; i <= n; i++) { update(str[i] - 'a', i, 1); } int q; cin >> q; while (q--) { int type; cin >> type; if (type == 1) { int ind; char c; cin >> ind >> c; int w = c - 'a'; update(str[ind] - 'a', ind, -1); update(w, ind, 1); str[ind] = c; } else { int l, r; cin >> l >> r; int ans = 0; for (int i = 0; i < 26; i++) { int c = query(i, r) - query(i, l - 1); ans += (c >= 1); } cout << ans << endl; } } return 0; }
replace
123
124
123
124
0
p02763
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int seg(int l, int r, int n, int nl, int nr, vector<int> &t) { if (r <= nl || nr <= l) return 0; else if (l <= nl && nr <= r) return t[n]; else { int mid = (nl + nr) / 2; return seg(l, r, n * 2, nl, mid, t) + seg(l, r, n * 2 + 1, mid, nr, t); } } int main() { int n; cin >> n; string s; cin >> s; int N; for (int i = 2; i < n; i *= 2) N = i; N *= 2; vector<vector<int>> t(26, vector<int>(N * 2, 0)); for (int i = 0; i < n; i++) t[s[i] - 'a'][i + N]++; for (int i = 0; i < 26; i++) { for (int j = N - 1; j > 0; j--) t[i][j] = t[i][j * 2] + t[i][j * 2 + 1]; } int q; cin >> q; vector<int> x; for (int i = 0; i < q; i++) { int type, a; cin >> type >> a; if (type == 1) { char b; cin >> b; for (int j = N + a - 1; j > 0; j /= 2) { t[b - 'a'][j]++; t[s[a - 1] - 'a'][j]--; } s[a - 1] = b; } if (type == 2) { int b; cin >> b; int kind = 0; for (int j = 0; j < 26; j++) { if (seg(a - 1, b, 1, 0, N, t[j])) kind++; } x.push_back(kind); } } for (int i = 0; i < x.size(); i++) cout << x[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int seg(int l, int r, int n, int nl, int nr, vector<int> &t) { if (r <= nl || nr <= l) return 0; else if (l <= nl && nr <= r) return t[n]; else { int mid = (nl + nr) / 2; return seg(l, r, n * 2, nl, mid, t) + seg(l, r, n * 2 + 1, mid, nr, t); } } int main() { int n; cin >> n; string s; cin >> s; int N = 1; for (int i = 2; i < n; i *= 2) N = i; N *= 2; vector<vector<int>> t(26, vector<int>(N * 2, 0)); for (int i = 0; i < n; i++) t[s[i] - 'a'][i + N]++; for (int i = 0; i < 26; i++) { for (int j = N - 1; j > 0; j--) t[i][j] = t[i][j * 2] + t[i][j * 2 + 1]; } int q; cin >> q; vector<int> x; for (int i = 0; i < q; i++) { int type, a; cin >> type >> a; if (type == 1) { char b; cin >> b; for (int j = N + a - 1; j > 0; j /= 2) { t[b - 'a'][j]++; t[s[a - 1] - 'a'][j]--; } s[a - 1] = b; } if (type == 2) { int b; cin >> b; int kind = 0; for (int j = 0; j < 26; j++) { if (seg(a - 1, b, 1, 0, N, t[j])) kind++; } x.push_back(kind); } } for (int i = 0; i < x.size(); i++) cout << x[i] << endl; return 0; }
replace
17
18
17
18
0
p02763
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout << t << endl; } template <typename T, typename... Args> void print(T t, Args... args) { cout << t << " "; print(args...); } #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl '\n' #define int long long #define double long double int n; string s; int tree[1000005]; void build(int i, int l, int r) { if (l == r) { tree[i] = (1ll << (s[l - 1] - 'a')); return; } int mid = (l + r) / 2; build(i * 2, l, mid); build(i * 2 + 1, mid + 1, r); tree[i] = tree[i * 2] | tree[i * 2 + 1]; } void update(int i, int l, int r, int l1, int r1, int val) { if (l1 > r1 || l > r1 || l1 > r) return; if (l1 <= l && r <= r1) { tree[i] = (1ll << val); return; } int mid = (l + r) / 2; update(i * 2, l, mid, l1, r1, val); update(i * 2 + 1, mid + 1, r, l1, r1, val); tree[i] = tree[i * 2] | tree[i * 2 + 1]; } int query(int i, int l, int r, int l1, int r1) { if (l1 > r1 || l > r1 || l1 > r) return 0; if (l1 <= l && r <= r1) return tree[i]; int mid = (l + r) / 2; return query(i * 2, l, mid, l1, r1) | query(i * 2 + 1, mid + 1, r, l1, r1); } int32_t main() { IOS; cin >> n >> s; build(1, 1, n); int q; cin >> q; while (q--) { int type; cin >> type; if (type == 2) { int a, b; cin >> a >> b; print(__builtin_popcount(query(1, 1, n, a, b))); } else { int pos; char type; cin >> pos >> type; update(1, 1, n, pos, pos, type - 'a'); } } }
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout << t << endl; } template <typename T, typename... Args> void print(T t, Args... args) { cout << t << " "; print(args...); } #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl '\n' #define int long long #define double long double int n; string s; int tree[2000005]; void build(int i, int l, int r) { if (l == r) { tree[i] = (1ll << (s[l - 1] - 'a')); return; } int mid = (l + r) / 2; build(i * 2, l, mid); build(i * 2 + 1, mid + 1, r); tree[i] = tree[i * 2] | tree[i * 2 + 1]; } void update(int i, int l, int r, int l1, int r1, int val) { if (l1 > r1 || l > r1 || l1 > r) return; if (l1 <= l && r <= r1) { tree[i] = (1ll << val); return; } int mid = (l + r) / 2; update(i * 2, l, mid, l1, r1, val); update(i * 2 + 1, mid + 1, r, l1, r1, val); tree[i] = tree[i * 2] | tree[i * 2 + 1]; } int query(int i, int l, int r, int l1, int r1) { if (l1 > r1 || l > r1 || l1 > r) return 0; if (l1 <= l && r <= r1) return tree[i]; int mid = (l + r) / 2; return query(i * 2, l, mid, l1, r1) | query(i * 2 + 1, mid + 1, r, l1, r1); } int32_t main() { IOS; cin >> n >> s; build(1, 1, n); int q; cin >> q; while (q--) { int type; cin >> type; if (type == 2) { int a, b; cin >> a >> b; print(__builtin_popcount(query(1, 1, n, a, b))); } else { int pos; char type; cin >> pos >> type; update(1, 1, n, pos, pos, type - 'a'); } } }
replace
19
20
19
20
0
p02763
C++
Runtime Error
#pragma GCC target("avx2") #pragma GCC optimize("O3", "unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define fastIO() \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define RANDOM() \ random_device __rd; \ mt19937 __gen = mt19937(__rd()); \ uniform_int_distribution<int> __dis(0, MAXN); \ auto rnd = bind(__dis, __gen); const int MAXN = 1E6; const int maxn = 1 << 19; int BIT[26][maxn]; int lb(int x) { return x & -x; } void Add(int alpha, int idx, int val) { for (; idx < maxn; idx += lb(idx)) BIT[alpha][idx] += val; } int Sum(int alpha, int idxL, int idxR, int sum = 0) { --idxL; for (; idxR; idxR -= lb(idxR)) sum += BIT[alpha][idxR]; for (; idxL; idxL -= lb(idxL)) sum -= BIT[alpha][idxL]; return sum; } int32_t main() { fastIO(); int n, q, op, idx, l, r, cnt; char c; string s; cin >> n >> s >> q; for (int i = 0; i < n; ++i) Add(s[i] - 'a', i + 1, 1); while (q--) { cin >> op; if (op == 1) { cin >> idx >> c; Add(s[idx] - 'a', idx + 1, -1); s[idx] = c; Add(s[idx] - 'a', idx + 1, 1); } else { cin >> l >> r, cnt = 0; for (int i = 0; i < 26; ++i) cnt += (Sum(i, l, r) > 0); cout << cnt << "\n"; } } return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3", "unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define fastIO() \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define RANDOM() \ random_device __rd; \ mt19937 __gen = mt19937(__rd()); \ uniform_int_distribution<int> __dis(0, MAXN); \ auto rnd = bind(__dis, __gen); const int MAXN = 1E6; const int maxn = 1 << 19; int BIT[26][maxn]; int lb(int x) { return x & -x; } void Add(int alpha, int idx, int val) { for (; idx < maxn; idx += lb(idx)) BIT[alpha][idx] += val; } int Sum(int alpha, int idxL, int idxR, int sum = 0) { --idxL; for (; idxR; idxR -= lb(idxR)) sum += BIT[alpha][idxR]; for (; idxL; idxL -= lb(idxL)) sum -= BIT[alpha][idxL]; return sum; } int32_t main() { fastIO(); int n, q, op, idx, l, r, cnt; char c; string s; cin >> n >> s >> q; for (int i = 0; i < n; ++i) Add(s[i] - 'a', i + 1, 1); while (q--) { cin >> op; if (op == 1) { cin >> idx >> c, --idx; Add(s[idx] - 'a', idx + 1, -1); s[idx] = c; Add(s[idx] - 'a', idx + 1, 1); } else { cin >> l >> r, cnt = 0; for (int i = 0; i < 26; ++i) cnt += (Sum(i, l, r) > 0); cout << cnt << "\n"; } } return 0; }
replace
52
53
52
53
-11
p02763
C++
Runtime Error
#include <bits/stdc++.h> #include <string> using namespace std; #define ll long long #define ull unsigned long long #define si(X) scanf("%d", &(X)) #define sll(X) scanf("%lld", &(X)) #define INFL 0x3f3f3f3f3f3f3f3fLL const int mod = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll expo(ll base, ll pow) { ll ans = 1; while (pow != 0) { if (pow & 1 == 1) { ans = ans * base; ans = ans % mod; } base *= base; base %= mod; pow /= 2; } return ans; } ll inv(ll x) { return expo(x, mod - 2); } const int M = 2e5 + 5; int arr[M], n; int segTree[4 * M][26]; void merge(int node) { for (int i = 0; i < 26; i++) { segTree[node][i] = segTree[2 * node][i] + segTree[2 * node + 1][i]; } } void build(int node, int l, int r) { if (l > r) return; if (l == r) { segTree[node][arr[l]] = 1; return; } int mid = (l + r) / 2; build(2 * node, l, mid); build(2 * node + 1, mid + 1, r); merge(node); } void update(int node, int l, int r, int point, int val) { if (l > point || r < point) return; if (l == r) { for (int i = 0; i < 26; i++) { segTree[node][i] = 0; } segTree[node][val] = 1; return; } int mid = (l + r) / 2; update(2 * node, l, mid, point, val); update(2 * node + 1, mid + 1, r, point, val); merge(node); } vector<int> query(int node, int l, int r, int ql, int qr) { vector<int> vec; if (l > qr || r < ql) return vec; if (l >= ql && r <= qr) { for (int i = 0; i < 26; i++) { if (segTree[node][i] > 0) vec.push_back(i); } return vec; } int mid = (l + r) / 2; vector<int> v1 = query(2 * node, l, mid, ql, qr); vector<int> v2 = query(2 * node + 1, mid + 1, r, ql, qr); set<int> se; for (int i = 0; i < v1.size(); i++) { if (se.count(v1[i])) continue; se.insert(v1[i]); vec.push_back(v1[i]); } for (int i = 0; i < v2.size(); i++) { if (se.count(v2[i])) continue; se.insert(v2[i]); vec.push_back(v2[i]); } return vec; } int main() { si(n); string str; cin >> str; for (int i = 0; i < n; i++) { arr[i + 1] = str[i] - 'a'; } build(1, 1, n); int q; si(q); while (q--) { int typ; si(typ); if (typ == 1) { int pos; char ex; si(pos); cin >> ex; update(1, 1, n, pos, ex - 'a'); } else { int ql, qr; si(ql); si(qr); /* vector<int> v1= query(1 , 1 , n , ql , qr); for(int i = 0 ; i < v1.size() ; i++){ cout<<v1[i]<<endl; }*/ printf("%d\n", query(1, 1, n, ql, qr).size()); } } }
#include <bits/stdc++.h> #include <string> using namespace std; #define ll long long #define ull unsigned long long #define si(X) scanf("%d", &(X)) #define sll(X) scanf("%lld", &(X)) #define INFL 0x3f3f3f3f3f3f3f3fLL const int mod = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll expo(ll base, ll pow) { ll ans = 1; while (pow != 0) { if (pow & 1 == 1) { ans = ans * base; ans = ans % mod; } base *= base; base %= mod; pow /= 2; } return ans; } ll inv(ll x) { return expo(x, mod - 2); } const int M = 5e5 + 5; int arr[M], n; int segTree[4 * M][26]; void merge(int node) { for (int i = 0; i < 26; i++) { segTree[node][i] = segTree[2 * node][i] + segTree[2 * node + 1][i]; } } void build(int node, int l, int r) { if (l > r) return; if (l == r) { segTree[node][arr[l]] = 1; return; } int mid = (l + r) / 2; build(2 * node, l, mid); build(2 * node + 1, mid + 1, r); merge(node); } void update(int node, int l, int r, int point, int val) { if (l > point || r < point) return; if (l == r) { for (int i = 0; i < 26; i++) { segTree[node][i] = 0; } segTree[node][val] = 1; return; } int mid = (l + r) / 2; update(2 * node, l, mid, point, val); update(2 * node + 1, mid + 1, r, point, val); merge(node); } vector<int> query(int node, int l, int r, int ql, int qr) { vector<int> vec; if (l > qr || r < ql) return vec; if (l >= ql && r <= qr) { for (int i = 0; i < 26; i++) { if (segTree[node][i] > 0) vec.push_back(i); } return vec; } int mid = (l + r) / 2; vector<int> v1 = query(2 * node, l, mid, ql, qr); vector<int> v2 = query(2 * node + 1, mid + 1, r, ql, qr); set<int> se; for (int i = 0; i < v1.size(); i++) { if (se.count(v1[i])) continue; se.insert(v1[i]); vec.push_back(v1[i]); } for (int i = 0; i < v2.size(); i++) { if (se.count(v2[i])) continue; se.insert(v2[i]); vec.push_back(v2[i]); } return vec; } int main() { si(n); string str; cin >> str; for (int i = 0; i < n; i++) { arr[i + 1] = str[i] - 'a'; } build(1, 1, n); int q; si(q); while (q--) { int typ; si(typ); if (typ == 1) { int pos; char ex; si(pos); cin >> ex; update(1, 1, n, pos, ex - 'a'); } else { int ql, qr; si(ql); si(qr); /* vector<int> v1= query(1 , 1 , n , ql , qr); for(int i = 0 ; i < v1.size() ; i++){ cout<<v1[i]<<endl; }*/ printf("%d\n", query(1, 1, n, ql, qr).size()); } } }
replace
29
30
29
30
0
p02764
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <queue> using namespace std; struct Node { double x, y, r; Node(double x, double y, double r) : x(x), y(y), r(r) {} }; int n, k; vector<int> x, y, c; double distance(double px, double py) { vector<double> dis(n); for (int i = 0; i < n; ++i) { dis[i] = c[i] * hypot(px - x[i], py - y[i]); } nth_element(dis.begin(), dis.begin() + k - 1, dis.end()); return dis[k - 1]; } double distance_lb(double px, double py, double r) { vector<double> dis(n); for (int i = 0; i < n; ++i) { dis[i] = c[i] * hypot(max(abs(px - x[i]) - r, 0.0), max(abs(py - y[i]) - r, 0.0)); } nth_element(dis.begin(), dis.begin() + k - 1, dis.end()); return dis[k - 1]; } int main() { cin >> n >> k; x.resize(n); y.resize(n); c.resize(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> c[i]; } queue<Node> que; double res = distance(0, 0); que.emplace(0, 0, 1000); while (!que.empty()) { auto node = que.front(); que.pop(); for (double dx : {-0.5, 0.5}) { for (double dy : {-0.5, 0.5}) { double nx = node.x + dx * node.r, ny = node.y + dy * node.r, nr = node.r / 2; double dis_lb = distance_lb(nx, ny, nr); if (res - dis_lb > 5e-7) { res = min(res, distance(nx, ny)); que.emplace(nx, ny, nr); } } } } cout << fixed << setprecision(15) << res << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <queue> using namespace std; struct Node { double x, y, r; Node(double x, double y, double r) : x(x), y(y), r(r) {} }; int n, k; vector<int> x, y, c; double distance(double px, double py) { vector<double> dis(n); for (int i = 0; i < n; ++i) { dis[i] = c[i] * hypot(px - x[i], py - y[i]); } nth_element(dis.begin(), dis.begin() + k - 1, dis.end()); return dis[k - 1]; } double distance_lb(double px, double py, double r) { vector<double> dis(n); for (int i = 0; i < n; ++i) { dis[i] = c[i] * hypot(max(abs(px - x[i]) - r, 0.0), max(abs(py - y[i]) - r, 0.0)); } nth_element(dis.begin(), dis.begin() + k - 1, dis.end()); return dis[k - 1]; } int main() { cin >> n >> k; x.resize(n); y.resize(n); c.resize(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> c[i]; } queue<Node> que; double res = distance(0, 0); que.emplace(0, 0, 1000); while (!que.empty()) { auto node = que.front(); que.pop(); for (double dx : {-0.5, 0.5}) { for (double dy : {-0.5, 0.5}) { double nx = node.x + dx * node.r, ny = node.y + dy * node.r, nr = node.r / 2; double dis_lb = distance_lb(nx, ny, nr); if (res - dis_lb > 5e-7 * max(1.0, dis_lb)) { res = min(res, distance(nx, ny)); que.emplace(nx, ny, nr); } } } } cout << fixed << setprecision(15) << res << endl; }
replace
55
56
55
56
TLE
p02764
C++
Time Limit Exceeded
#include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; struct point { double x, y; }; int n, k, EPS = 1000; double l = 0, ri = 1E10; vector<point> p; vector<double> c; double len(point a, point b) { return hypot((a.x - b.x), (a.y - b.y)); } bool yet_ok(double t) { if (n == 1) return true; vector<double> r(n); for (int i = 0; i < n; i++) r[i] = t / c[i]; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { if (len(p[i], p[j]) > r[i] + r[j]) continue; if (len(p[i], p[j]) < fabs(r[i] - r[j])) continue; double a1 = -2 * (p[i].x - p[j].x); double b1 = -2 * (p[i].y - p[j].y); double c1 = p[i].x * p[i].x - p[j].x * p[j].x + p[i].y * p[i].y - p[j].y * p[j].y - r[i] * r[i] + r[j] * r[j]; point o; int cnt = 0; double d1 = len({0, 0}, {a1, b1}); a1 /= d1; b1 /= d1; c1 /= d1; d1 = a1 * p[i].x + b1 * p[i].y + c1; o = {p[i].x - a1 * d1, p[i].y - b1 * d1}; double move = sqrt(r[i] * r[i] - d1 * d1); vector<point> all_dots = {{o.x + b1 * move, o.y - a1 * move}, {o.x - b1 * move, o.y + a1 * move}}; for (auto v : all_dots) { cnt = 0; o = v; for (int q = 0; q < n; q++) if (len(p[q], o) <= r[q] || q == i || q == j) cnt++; if (cnt >= k) return true; } } for (auto o : p) { int cnt = 0; for (int q = 0; q < n; q++) if (len(p[q], o) <= r[q]) cnt++; if (cnt >= k) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; p.resize(n); c.resize(n); for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y >> c[i]; for (int it = 0; it < EPS; it++) { double m = (l + ri) / 2; if (yet_ok(m)) ri = m; else l = m; } cout << fixed << setprecision(20); cout << ri << "\n"; return 0; }
#include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; struct point { double x, y; }; int n, k, EPS = 100; double l = 0, ri = 1E10; vector<point> p; vector<double> c; double len(point a, point b) { return hypot((a.x - b.x), (a.y - b.y)); } bool yet_ok(double t) { if (n == 1) return true; vector<double> r(n); for (int i = 0; i < n; i++) r[i] = t / c[i]; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { if (len(p[i], p[j]) > r[i] + r[j]) continue; if (len(p[i], p[j]) < fabs(r[i] - r[j])) continue; double a1 = -2 * (p[i].x - p[j].x); double b1 = -2 * (p[i].y - p[j].y); double c1 = p[i].x * p[i].x - p[j].x * p[j].x + p[i].y * p[i].y - p[j].y * p[j].y - r[i] * r[i] + r[j] * r[j]; point o; int cnt = 0; double d1 = len({0, 0}, {a1, b1}); a1 /= d1; b1 /= d1; c1 /= d1; d1 = a1 * p[i].x + b1 * p[i].y + c1; o = {p[i].x - a1 * d1, p[i].y - b1 * d1}; double move = sqrt(r[i] * r[i] - d1 * d1); vector<point> all_dots = {{o.x + b1 * move, o.y - a1 * move}, {o.x - b1 * move, o.y + a1 * move}}; for (auto v : all_dots) { cnt = 0; o = v; for (int q = 0; q < n; q++) if (len(p[q], o) <= r[q] || q == i || q == j) cnt++; if (cnt >= k) return true; } } for (auto o : p) { int cnt = 0; for (int q = 0; q < n; q++) if (len(p[q], o) <= r[q]) cnt++; if (cnt >= k) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; p.resize(n); c.resize(n); for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y >> c[i]; for (int it = 0; it < EPS; it++) { double m = (l + ri) / 2; if (yet_ok(m)) ri = m; else l = m; } cout << fixed << setprecision(20); cout << ri << "\n"; return 0; }
replace
10
11
10
11
TLE
p02764
C++
Runtime Error
#include "bits/stdc++.h" #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define MSVC_UNKO(x) x #define rep(...) \ MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define all(c) c.begin(), c.end() #define write(x) cout << (x) << '\n' using namespace std; typedef long long ll; template <class T> using vv = vector<vector<T>>; template <class T> auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; } aaaa; constexpr double EPS = 1e-3; int main() { int N, K; cin >> N >> K; vector<int> X(N), Y(N), C(N); rep(i, N) cin >> X[i] >> Y[i] >> C[i]; if (K == 1) { write(0); return 0; } double low = 0, high = 3e5; rep(it, 60) { double mid = (low + high) / 2; // mid = 3; bool ok = false; rep(i, N - 1) rep(j, i + 1, N) { double d = hypot(X[i] - X[j], Y[i] - Y[j]); if (d * (C[i] * C[j]) > mid * (C[j] + C[i])) { continue; } rep(p, 2) { double x, y; if (d * (C[i] * C[j]) < mid * abs(C[j] - C[i])) { if (C[i] < C[j]) x = X[j], y = Y[j]; else x = X[i], y = Y[i]; } else { double d2 = pow(d, 2); double a = (d2 + pow(mid / C[i], 2) - pow(mid / C[j], 2)) / 2; double b = d2 * pow(mid / C[i], 2) - a * a + EPS; // if (b < 0) cerr << b << endl; assert(b >= 0); x = (a * (X[j] - X[i]) + (-2 * p + 1) * (Y[j] - Y[i]) * sqrt(b)) / d2 + X[i]; y = (a * (Y[j] - Y[i]) + (+2 * p - 1) * (X[j] - X[i]) * sqrt(b)) / d2 + Y[i]; } int cnt = 0; rep(k, N) { if (k == i || k == j) cnt++; else if (hypot(x - X[k], y - Y[k]) * C[k] <= mid) cnt++; } if (cnt >= K) ok = true; } if (ok) break; } if (ok) high = mid; else low = mid; } write(high); }
#include "bits/stdc++.h" #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define MSVC_UNKO(x) x #define rep(...) \ MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define all(c) c.begin(), c.end() #define write(x) cout << (x) << '\n' using namespace std; typedef long long ll; template <class T> using vv = vector<vector<T>>; template <class T> auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; } aaaa; constexpr double EPS = 1e-3; int main() { int N, K; cin >> N >> K; vector<int> X(N), Y(N), C(N); rep(i, N) cin >> X[i] >> Y[i] >> C[i]; if (K == 1) { write(0); return 0; } double low = 0, high = 3e5; rep(it, 60) { double mid = (low + high) / 2; // mid = 3; bool ok = false; rep(i, N - 1) rep(j, i + 1, N) { double d = hypot(X[i] - X[j], Y[i] - Y[j]); if (d * (C[i] * C[j]) > mid * (C[j] + C[i])) { continue; } rep(p, 2) { double x, y; if (d * (C[i] * C[j]) < mid * abs(C[j] - C[i])) { if (C[i] < C[j]) x = X[j], y = Y[j]; else x = X[i], y = Y[i]; } else { double d2 = pow(d, 2); double a = (d2 + pow(mid / C[i], 2) - pow(mid / C[j], 2)) / 2; double b = d2 * pow(mid / C[i], 2) - a * a + EPS; // if (b < 0) cerr << b << endl; // assert(b >= 0); x = (a * (X[j] - X[i]) + (-2 * p + 1) * (Y[j] - Y[i]) * sqrt(b)) / d2 + X[i]; y = (a * (Y[j] - Y[i]) + (+2 * p - 1) * (X[j] - X[i]) * sqrt(b)) / d2 + Y[i]; } int cnt = 0; rep(k, N) { if (k == i || k == j) cnt++; else if (hypot(x - X[k], y - Y[k]) * C[k] <= mid) cnt++; } if (cnt >= K) ok = true; } if (ok) break; } if (ok) high = mid; else low = mid; } write(high); }
replace
60
61
60
61
0
p02764
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } /* <url:> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } // 点の入力 bool eq(ld a, ld b) { return (abs(a - b) < eps); } // 誤差つき等号判定 ld dot(Point a, Point b) { return real(conj(a) * b); } // 内積 ld cross(Point a, Point b) { return imag(conj(a) * b); } // 外積 // 直線の定義 class Line { public: Point a, b; Line() : a(Point(0, 0)), b(Point(0, 0)) {} Line(Point a, Point b) : a(a), b(b) {} Point operator[](const int _num) { if (_num == 0) return a; else if (_num == 1) return b; else assert(false); } }; // 円の定義 class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; // 垂線の足 Point proj(Line l, Point p) { ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + t * (l.a - l.b); } // CCW int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; // a,b,cが反時計周りの順に並ぶ if (cross(b, c) < -eps) return -1; // a,b,cが時計周りの順に並ぶ if (dot(b, c) < 0) return 2; // c,a,bの順に直線に並ぶ if (norm(b) < norm(c)) return -2; // a,b,cの順に直線に並ぶ return 0; // a,c,bの順に直線に並ぶ } /* 交差判定 */ // 直線と直線の交差判定 bool isis_ll(Line l, Line m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } // 直線と線分の交差判定 bool isis_ls(Line l, Line s) { return isis_ll(l, s) && (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps); } // 線分と線分の交差判定 bool isis_ss(Line s, Line t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } // 点の直線上判定 bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < eps); } // 点の線分上判定 bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps); } /* 距離 */ // 直線と直線の交点 Point is_ll(Line s, Line t) { Point sv = s.b - s.a, tv = t.b - t.a; assert(cross(sv, tv) != 0); return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv); } // 直線と点の距離 ld dist_lp(Line l, Point p) { return abs(p - proj(l, p)); } // 直線と直線の距離 ld dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } // 直線と線分の距離 ld dist_ls(Line l, Line s) { return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } // 線分と点の距離 ld dist_sp(Line s, Point p) { Point r = proj(s, p); return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } // 線分と線分の距離 ld dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } /* 円 */ // 円と円の交点 vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } // 円と直線の交点 vector<Point> is_lc(Circle c, Line l) { vector<Point> res; ld d = dist_lp(l, c.p); if (d < c.r + eps) { ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety; Point nor = (l.a - l.b) / abs(l.a - l.b); res.push_back(proj(l, c.p) + len * nor); res.push_back(proj(l, c.p) - len * nor); } return res; } // 円と線分の距離 vector<Point> is_sc(Circle c, Line l) { vector<Point> v = is_lc(c, l), res; for (Point p : v) if (isis_sp(l, p)) res.push_back(p); return res; } // 円と点の接線 vector<Line> tangent_cp(Circle c, Point p) { vector<Line> ret; Point v = c.p - p; ld d = abs(v); ld l = sqrt(norm(v) - c.r * c.r); if (isnan(l)) { return ret; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); ret.push_back(Line(p, p + v1)); if (l < eps) return ret; ret.push_back(Line(p, p + v2)); return ret; } // 円と円の接線 vector<Line> tangent_cc(Circle c1, Circle c2) { vector<Line> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > eps) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nret = tangent_cp(c1, out); ret.insert(ret.end(), nret.begin(), nret.end()); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; ret.push_back(Line(q1, q1 + v)); ret.push_back(Line(q2, q2 + v)); } return ret; } template <class Type> Type solve(Type res = Type()) { int N, K; cin >> N >> K; vector<int> x(N), y(N), c(N); for (int i = 0; i < N; i++) { cin >> x[i] >> y[i] >> c[i]; } auto check = [&](double m) { vector<Circle> Cs(N); for (int i = 0; i < N; i++) { Cs[i].p = Point(x[i], y[i]); Cs[i].r = m / c[i]; } vector<Point> cands; for (int i = 0; i < N; i++) { cands.emplace_back(Cs[i].p); for (int j = i + 1; j < N; j++) { for (const Point &p : is_cc(Cs[i], Cs[j])) { cands.emplace_back(p); } } } bool ok = false; for (const Point &p : cands) { int cnt = 0; for (int i = 0; i < N; i++) { if (abs(Cs[i].p - p) < Cs[i].r + eps) { cnt++; } } if (cnt >= K) { ok = true; break; } } return ok; }; double l = 0, r = INF; for (int unchi = 0; unchi < 1000; unchi++) { double m = (l + r) / 2; if (check(m)) { r = m; } else { l = m; } } res = r; return res; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); // solve<ll>(0); cout << fixed << setprecision(12) << solve<double>() << endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } /* <url:> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } // 点の入力 bool eq(ld a, ld b) { return (abs(a - b) < eps); } // 誤差つき等号判定 ld dot(Point a, Point b) { return real(conj(a) * b); } // 内積 ld cross(Point a, Point b) { return imag(conj(a) * b); } // 外積 // 直線の定義 class Line { public: Point a, b; Line() : a(Point(0, 0)), b(Point(0, 0)) {} Line(Point a, Point b) : a(a), b(b) {} Point operator[](const int _num) { if (_num == 0) return a; else if (_num == 1) return b; else assert(false); } }; // 円の定義 class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; // 垂線の足 Point proj(Line l, Point p) { ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + t * (l.a - l.b); } // CCW int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; // a,b,cが反時計周りの順に並ぶ if (cross(b, c) < -eps) return -1; // a,b,cが時計周りの順に並ぶ if (dot(b, c) < 0) return 2; // c,a,bの順に直線に並ぶ if (norm(b) < norm(c)) return -2; // a,b,cの順に直線に並ぶ return 0; // a,c,bの順に直線に並ぶ } /* 交差判定 */ // 直線と直線の交差判定 bool isis_ll(Line l, Line m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } // 直線と線分の交差判定 bool isis_ls(Line l, Line s) { return isis_ll(l, s) && (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps); } // 線分と線分の交差判定 bool isis_ss(Line s, Line t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } // 点の直線上判定 bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < eps); } // 点の線分上判定 bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps); } /* 距離 */ // 直線と直線の交点 Point is_ll(Line s, Line t) { Point sv = s.b - s.a, tv = t.b - t.a; assert(cross(sv, tv) != 0); return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv); } // 直線と点の距離 ld dist_lp(Line l, Point p) { return abs(p - proj(l, p)); } // 直線と直線の距離 ld dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } // 直線と線分の距離 ld dist_ls(Line l, Line s) { return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } // 線分と点の距離 ld dist_sp(Line s, Point p) { Point r = proj(s, p); return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } // 線分と線分の距離 ld dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } /* 円 */ // 円と円の交点 vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } // 円と直線の交点 vector<Point> is_lc(Circle c, Line l) { vector<Point> res; ld d = dist_lp(l, c.p); if (d < c.r + eps) { ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety; Point nor = (l.a - l.b) / abs(l.a - l.b); res.push_back(proj(l, c.p) + len * nor); res.push_back(proj(l, c.p) - len * nor); } return res; } // 円と線分の距離 vector<Point> is_sc(Circle c, Line l) { vector<Point> v = is_lc(c, l), res; for (Point p : v) if (isis_sp(l, p)) res.push_back(p); return res; } // 円と点の接線 vector<Line> tangent_cp(Circle c, Point p) { vector<Line> ret; Point v = c.p - p; ld d = abs(v); ld l = sqrt(norm(v) - c.r * c.r); if (isnan(l)) { return ret; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); ret.push_back(Line(p, p + v1)); if (l < eps) return ret; ret.push_back(Line(p, p + v2)); return ret; } // 円と円の接線 vector<Line> tangent_cc(Circle c1, Circle c2) { vector<Line> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > eps) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nret = tangent_cp(c1, out); ret.insert(ret.end(), nret.begin(), nret.end()); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; ret.push_back(Line(q1, q1 + v)); ret.push_back(Line(q2, q2 + v)); } return ret; } template <class Type> Type solve(Type res = Type()) { int N, K; cin >> N >> K; vector<int> x(N), y(N), c(N); for (int i = 0; i < N; i++) { cin >> x[i] >> y[i] >> c[i]; } auto check = [&](double m) { vector<Circle> Cs(N); for (int i = 0; i < N; i++) { Cs[i].p = Point(x[i], y[i]); Cs[i].r = m / c[i]; } vector<Point> cands; for (int i = 0; i < N; i++) { cands.emplace_back(Cs[i].p); for (int j = i + 1; j < N; j++) { for (const Point &p : is_cc(Cs[i], Cs[j])) { cands.emplace_back(p); } } } bool ok = false; for (const Point &p : cands) { int cnt = 0; for (int i = 0; i < N; i++) { if (abs(Cs[i].p - p) < Cs[i].r + eps) { cnt++; } } if (cnt >= K) { ok = true; break; } } return ok; }; double l = 0, r = INF; for (int unchi = 0; unchi < 300; unchi++) { double m = (l + r) / 2; if (check(m)) { r = m; } else { l = m; } } res = r; return res; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); // solve<ll>(0); cout << fixed << setprecision(12) << solve<double>() << endl; return 0; }
replace
305
306
305
306
TLE
p02764
C++
Time Limit Exceeded
#include <cmath> #include <iomanip> #include <iostream> using namespace std; typedef pair<double, double> P; typedef pair<P, P> PP; const double INF = 1e100; pair<pair<double, double>, pair<double, double>> circle_cross_point(double x0, double y0, double r0, double x1, double y1, double r1) { if ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) > (r0 + r1) * (r0 + r1) || (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) < (r0 - r1) * (r0 - r1)) { return pair<pair<double, double>, pair<double, double>>( pair<double, double>(INF, INF), pair<double, double>(INF, INF)); } double a = ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + r0 * r0 - r1 * r1) / 2; double z = ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); return pair<pair<double, double>, pair<double, double>>( pair<double, double>( (a * (x1 - x0) + (y1 - y0) * sqrt(z * r0 * r0 - a * a)) / z + x0, (a * (y1 - y0) - (x1 - x0) * sqrt(z * r0 * r0 - a * a)) / z + y0), pair<double, double>( (a * (x1 - x0) - (y1 - y0) * sqrt(z * r0 * r0 - a * a)) / z + x0, (a * (y1 - y0) + (x1 - x0) * sqrt(z * r0 * r0 - a * a)) / z + y0)); } int main() { int n, k; cin >> n >> k; double x[100], y[100], c[100]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> c[i]; double left = 0, right = 1e8; while (right - left > right * 1e-8) { double mid = (right + left) / 2; bool f = false; for (int i = 0; i < n; i++) { int d = 0; for (int j = 0; j < n; j++) { if ((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]) - right * 1e-8 < (mid / c[j]) * (mid / c[j])) d++; } if (d >= k) f = true; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { PP p = circle_cross_point(x[i], y[i], mid / c[i], x[j], y[j], mid / c[j]); double u = p.first.first, v = p.first.second; int d = 0; for (int l = 0; l < n; l++) { if ((x[l] - u) * (x[l] - u) + (y[l] - v) * (y[l] - v) - right * 1e-8 < (mid / c[l]) * (mid / c[l])) d++; } if (d >= k) f = true; u = p.second.first, v = p.second.second; d = 0; for (int l = 0; l < n; l++) { if ((x[l] - u) * (x[l] - u) + (y[l] - v) * (y[l] - v) - right * 1e-8 < (mid / c[l]) * (mid / c[l])) d++; } if (d >= k) f = true; } } if (f) right = mid; else left = mid; } cout << fixed << setprecision(15) << right << endl; }
#include <cmath> #include <iomanip> #include <iostream> using namespace std; typedef pair<double, double> P; typedef pair<P, P> PP; const double INF = 1e100; pair<pair<double, double>, pair<double, double>> circle_cross_point(double x0, double y0, double r0, double x1, double y1, double r1) { if ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) > (r0 + r1) * (r0 + r1) || (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) < (r0 - r1) * (r0 - r1)) { return pair<pair<double, double>, pair<double, double>>( pair<double, double>(INF, INF), pair<double, double>(INF, INF)); } double a = ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + r0 * r0 - r1 * r1) / 2; double z = ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); return pair<pair<double, double>, pair<double, double>>( pair<double, double>( (a * (x1 - x0) + (y1 - y0) * sqrt(z * r0 * r0 - a * a)) / z + x0, (a * (y1 - y0) - (x1 - x0) * sqrt(z * r0 * r0 - a * a)) / z + y0), pair<double, double>( (a * (x1 - x0) - (y1 - y0) * sqrt(z * r0 * r0 - a * a)) / z + x0, (a * (y1 - y0) + (x1 - x0) * sqrt(z * r0 * r0 - a * a)) / z + y0)); } int main() { int n, k; cin >> n >> k; double x[100], y[100], c[100]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> c[i]; double left = 0, right = 1e8; while (right - left > right * 1e-8 && right - left > 1e-12) { double mid = (right + left) / 2; bool f = false; for (int i = 0; i < n; i++) { int d = 0; for (int j = 0; j < n; j++) { if ((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]) - right * 1e-8 < (mid / c[j]) * (mid / c[j])) d++; } if (d >= k) f = true; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { PP p = circle_cross_point(x[i], y[i], mid / c[i], x[j], y[j], mid / c[j]); double u = p.first.first, v = p.first.second; int d = 0; for (int l = 0; l < n; l++) { if ((x[l] - u) * (x[l] - u) + (y[l] - v) * (y[l] - v) - right * 1e-8 < (mid / c[l]) * (mid / c[l])) d++; } if (d >= k) f = true; u = p.second.first, v = p.second.second; d = 0; for (int l = 0; l < n; l++) { if ((x[l] - u) * (x[l] - u) + (y[l] - v) * (y[l] - v) - right * 1e-8 < (mid / c[l]) * (mid / c[l])) d++; } if (d >= k) f = true; } } if (f) right = mid; else left = mid; } cout << fixed << setprecision(15) << right << endl; }
replace
36
37
36
37
TLE
p02764
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <functional> #include <iostream> #include <limits> #include <sstream> #include <string> #include <queue> #include <vector> using namespace std; int N, K; vector<tuple<int, int, int>> info; double nth_distance(double x, double y) { vector<double> dist(N); for (int i = 0; i < N; i++) { dist[i] = get<2>(info[i]) * hypot(x - get<0>(info[i]), y - get<1>(info[i])); } nth_element(dist.begin(), dist.begin() + K - 1, dist.end()); return dist[K - 1]; } double nth_distance_lb(double x, double y, double r) { vector<double> dist(N); for (int i = 0; i < N; i++) { dist[i] = get<2>(info[i]) * hypot(max(abs(x - get<0>(info[i])) - r, 0.0), max(abs(y - get<1>(info[i])) - r, 0.0)); } nth_element(dist.begin(), dist.begin() + K - 1, dist.end()); return dist[K - 1]; } const double eps = 1e-6; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> N >> K; for (int i = 0; i < N; i++) { int x, y, c; cin >> x >> y >> c; info.emplace_back(x, y, c); } double result = 1e9; queue<tuple<double, double, double>> q; q.emplace(0, 0, 1000); while (!q.empty()) { double x, y, r; tie(x, y, r) = q.front(); q.pop(); double lb = nth_distance_lb(x, y, r); if (result - lb > eps) { result = min(result, nth_distance(x, y)); for (double dx : {-0.5, 0.5}) { for (double dy : {-0.5, 0.5}) { q.emplace(x + dx * r, y + dy * r, r / 2.0); } } } } cout.setf(ios::fixed); cout.precision(15); cout << result; return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <functional> #include <iostream> #include <limits> #include <sstream> #include <string> #include <queue> #include <vector> using namespace std; int N, K; vector<tuple<int, int, int>> info; double nth_distance(double x, double y) { vector<double> dist(N); for (int i = 0; i < N; i++) { dist[i] = get<2>(info[i]) * hypot(x - get<0>(info[i]), y - get<1>(info[i])); } nth_element(dist.begin(), dist.begin() + K - 1, dist.end()); return dist[K - 1]; } double nth_distance_lb(double x, double y, double r) { vector<double> dist(N); for (int i = 0; i < N; i++) { dist[i] = get<2>(info[i]) * hypot(max(abs(x - get<0>(info[i])) - r, 0.0), max(abs(y - get<1>(info[i])) - r, 0.0)); } nth_element(dist.begin(), dist.begin() + K - 1, dist.end()); return dist[K - 1]; } const double eps = 1e-6; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> N >> K; for (int i = 0; i < N; i++) { int x, y, c; cin >> x >> y >> c; info.emplace_back(x, y, c); } double result = 1e9; queue<tuple<double, double, double>> q; q.emplace(0, 0, 1000); while (!q.empty()) { double x, y, r; tie(x, y, r) = q.front(); q.pop(); double lb = nth_distance_lb(x, y, r); if (result - lb > eps * max(1.0, lb)) { result = min(result, nth_distance(x, y)); for (double dx : {-0.5, 0.5}) { for (double dy : {-0.5, 0.5}) { q.emplace(x + dx * r, y + dy * r, r / 2.0); } } } } cout.setf(ios::fixed); cout.precision(15); cout << result; return 0; }
replace
64
65
64
65
TLE
p02764
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define all(v) (v).begin(), (v).end() #define io ios::sync_with_stdio(0) #define rep(i, a, b) for (int i = a; i <= b; i++) #define rson rt << 1 | 1, mid + 1, r #define lson rt << 1, l, mid #define lll __int128 #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define pb push_back #define eps 1e-12 #define int long long const int mod = 1e9 + 7; inline int ksm(int a, int b) { int ans = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ans = ans * a % mod; return ans; } const double PI = acos(-1.0); #define sqr(x) ((x) * (x)) const int N = 1010; double area[100]; int n, k; int dcmp(double x) { if (x < -eps) return -1; else return x > eps; } struct cp { double x, y, r, angle; double c; int d; cp() {} cp(double xx, double yy, double ang = 0, int t = 0) { x = xx; y = yy; angle = ang; d = t; } void get() { scanf("%lf%lf%lf", &x, &y, &r); d = 1; } } cir[N], tp[N * 2]; double dis(cp a, cp b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } double cross(cp p0, cp p1, cp p2) { return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x); } int CirCrossCir(cp p1, double r1, cp p2, double r2, cp &cp1, cp &cp2) { double mx = p2.x - p1.x, sx = p2.x + p1.x, mx2 = mx * mx; double my = p2.y - p1.y, sy = p2.y + p1.y, my2 = my * my; double sq = mx2 + my2, d = -(sq - sqr(r1 - r2)) * (sq - sqr(r1 + r2)); if (d + eps < 0) return 0; if (d < eps) d = 0; else d = sqrt(d); double x = mx * ((r1 + r2) * (r1 - r2) + mx * sx) + sx * my2; double y = my * ((r1 + r2) * (r1 - r2) + my * sy) + sy * mx2; double dx = mx * d, dy = my * d; sq *= 2; cp1.x = (x - dy) / sq; cp1.y = (y + dx) / sq; cp2.x = (x + dy) / sq; cp2.y = (y - dx) / sq; if (d > eps) return 2; else return 1; } bool circmp(const cp &u, const cp &v) { return dcmp(u.r - v.r) < 0; } bool cmp(const cp &u, const cp &v) { if (dcmp(u.angle - v.angle)) return u.angle < v.angle; return u.d > v.d; } double calc(cp cir, cp cp1, cp cp2) { double ans = (cp2.angle - cp1.angle) * sqr(cir.r) - cross(cir, cp1, cp2) + cross(cp(0, 0), cp1, cp2); return ans / 2; } void CirUnion(cp cir[], int n) { cp cp1, cp2; sort(cir, cir + n, circmp); for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (dcmp(dis(cir[i], cir[j]) + cir[i].r - cir[j].r) <= 0) cir[i].d++; for (int i = 0; i < n; ++i) { int tn = 0, cnt = 0; for (int j = 0; j < n; ++j) { if (i == j) continue; if (CirCrossCir(cir[i], cir[i].r, cir[j], cir[j].r, cp2, cp1) < 2) continue; cp1.angle = atan2(cp1.y - cir[i].y, cp1.x - cir[i].x); cp2.angle = atan2(cp2.y - cir[i].y, cp2.x - cir[i].x); cp1.d = 1; tp[tn++] = cp1; cp2.d = -1; tp[tn++] = cp2; if (dcmp(cp1.angle - cp2.angle) > 0) cnt++; } tp[tn++] = cp(cir[i].x - cir[i].r, cir[i].y, PI, -cnt); tp[tn++] = cp(cir[i].x - cir[i].r, cir[i].y, -PI, cnt); sort(tp, tp + tn, cmp); int p, s = cir[i].d + tp[0].d; for (int j = 1; j < tn; ++j) { p = s; s += tp[j].d; area[p] += calc(cir[i], tp[j - 1], tp[j]); } } } double solve(double mid) { // scanf("%d", &n); for (int i = 0; i < n; ++i) cir[i].r = mid / cir[i].c, cir[i].d = 1; memset(area, 0, sizeof(area)); CirUnion(cir, n); // 去掉重复计算的 for (int i = 1; i <= n; ++i) { area[i] -= area[i + 1]; } // area[i]为重叠了i次的面积 // tot 为总面积 double tot = 0; for (int i = k; i <= n; i++) tot += area[i]; // cout<<mid<<" "<<tot<<endl; return tot; // printf("%f\n", tot); } signed main() { io; cin >> n >> k; rep(i, 0, n - 1) { cin >> cir[i].x >> cir[i].y >> cir[i].c; } double ans = 1e40; double l = 0, r = 1e20; while (l + eps < r) { double mid = (l + r) / 2; double t = solve(mid); if (t > eps) ans = mid, r = mid - eps; else l = mid + eps; } cout << fixed << setprecision(10) << ans << endl; getchar(); // getchar(); }
#include "bits/stdc++.h" using namespace std; #define all(v) (v).begin(), (v).end() #define io ios::sync_with_stdio(0) #define rep(i, a, b) for (int i = a; i <= b; i++) #define rson rt << 1 | 1, mid + 1, r #define lson rt << 1, l, mid #define lll __int128 #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define pb push_back #define eps 1e-12 #define int long long const int mod = 1e9 + 7; inline int ksm(int a, int b) { int ans = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ans = ans * a % mod; return ans; } const double PI = acos(-1.0); #define sqr(x) ((x) * (x)) const int N = 1010; double area[100]; int n, k; int dcmp(double x) { if (x < -eps) return -1; else return x > eps; } struct cp { double x, y, r, angle; double c; int d; cp() {} cp(double xx, double yy, double ang = 0, int t = 0) { x = xx; y = yy; angle = ang; d = t; } void get() { scanf("%lf%lf%lf", &x, &y, &r); d = 1; } } cir[N], tp[N * 2]; double dis(cp a, cp b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } double cross(cp p0, cp p1, cp p2) { return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x); } int CirCrossCir(cp p1, double r1, cp p2, double r2, cp &cp1, cp &cp2) { double mx = p2.x - p1.x, sx = p2.x + p1.x, mx2 = mx * mx; double my = p2.y - p1.y, sy = p2.y + p1.y, my2 = my * my; double sq = mx2 + my2, d = -(sq - sqr(r1 - r2)) * (sq - sqr(r1 + r2)); if (d + eps < 0) return 0; if (d < eps) d = 0; else d = sqrt(d); double x = mx * ((r1 + r2) * (r1 - r2) + mx * sx) + sx * my2; double y = my * ((r1 + r2) * (r1 - r2) + my * sy) + sy * mx2; double dx = mx * d, dy = my * d; sq *= 2; cp1.x = (x - dy) / sq; cp1.y = (y + dx) / sq; cp2.x = (x + dy) / sq; cp2.y = (y - dx) / sq; if (d > eps) return 2; else return 1; } bool circmp(const cp &u, const cp &v) { return dcmp(u.r - v.r) < 0; } bool cmp(const cp &u, const cp &v) { if (dcmp(u.angle - v.angle)) return u.angle < v.angle; return u.d > v.d; } double calc(cp cir, cp cp1, cp cp2) { double ans = (cp2.angle - cp1.angle) * sqr(cir.r) - cross(cir, cp1, cp2) + cross(cp(0, 0), cp1, cp2); return ans / 2; } void CirUnion(cp cir[], int n) { cp cp1, cp2; sort(cir, cir + n, circmp); for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (dcmp(dis(cir[i], cir[j]) + cir[i].r - cir[j].r) <= 0) cir[i].d++; for (int i = 0; i < n; ++i) { int tn = 0, cnt = 0; for (int j = 0; j < n; ++j) { if (i == j) continue; if (CirCrossCir(cir[i], cir[i].r, cir[j], cir[j].r, cp2, cp1) < 2) continue; cp1.angle = atan2(cp1.y - cir[i].y, cp1.x - cir[i].x); cp2.angle = atan2(cp2.y - cir[i].y, cp2.x - cir[i].x); cp1.d = 1; tp[tn++] = cp1; cp2.d = -1; tp[tn++] = cp2; if (dcmp(cp1.angle - cp2.angle) > 0) cnt++; } tp[tn++] = cp(cir[i].x - cir[i].r, cir[i].y, PI, -cnt); tp[tn++] = cp(cir[i].x - cir[i].r, cir[i].y, -PI, cnt); sort(tp, tp + tn, cmp); int p, s = cir[i].d + tp[0].d; for (int j = 1; j < tn; ++j) { p = s; s += tp[j].d; area[p] += calc(cir[i], tp[j - 1], tp[j]); } } } double solve(double mid) { // scanf("%d", &n); for (int i = 0; i < n; ++i) cir[i].r = mid / cir[i].c, cir[i].d = 1; memset(area, 0, sizeof(area)); CirUnion(cir, n); // 去掉重复计算的 for (int i = 1; i <= n; ++i) { area[i] -= area[i + 1]; } // area[i]为重叠了i次的面积 // tot 为总面积 double tot = 0; for (int i = k; i <= n; i++) tot += area[i]; // cout<<mid<<" "<<tot<<endl; return tot; // printf("%f\n", tot); } signed main() { io; cin >> n >> k; rep(i, 0, n - 1) { cin >> cir[i].x >> cir[i].y >> cir[i].c; } double ans = 1e40; double l = 0, r = 1e20; int T = 800; while (T--) { double mid = (l + r) / 2; double t = solve(mid); if (t > eps) ans = mid, r = mid - eps; else l = mid + eps; } cout << fixed << setprecision(10) << ans << endl; getchar(); // getchar(); }
replace
159
160
159
161
TLE
p02764
C++
Time Limit Exceeded
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; using namespace std; using ll = long long; #define double long double using datas = pair<ll, ll>; using ddatas = pair<double, double>; using tdata = pair<ll, datas>; using vec = vector<ll>; using mat = vector<vec>; using pvec = vector<datas>; using pmat = vector<pvec>; // using // llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>; #define For(i, a, b) for (i = a; i < (ll)b; i++) #define bFor(i, a, b) for (i = a; i >= (ll)b; i--) #define rep(i, N) For(i, 0, N) #define rep1(i, N) For(i, 1, N) #define brep(i, N) bFor(i, N - 1, 0) #define all(v) (v).begin(), (v).end() #define allr(v) (v).rbegin(), (v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define endl "\n" #define pb push_back #define eb emplace_back #define print(v) cout << v << endl #define printyes cout << "Yes" << endl #define printno cout << "No" << endl #define printYES cout << "YES" << endl #define printNO cout << "NO" << endl #define output(v) \ do { \ bool f = 0; \ for (auto outi : v) { \ cout << (f ? " " : "") << outi; \ f = 1; \ } \ cout << endl; \ } while (0) const ll mod = 1000000007; const ll inf = 1LL << 60; const double PI = acos(-1); const double eps = 1e-9; template <class T> inline bool chmax(T &a, T b) { bool x = a < b; if (x) a = b; return x; } template <class T> inline bool chmin(T &a, T b) { bool x = a > b; if (x) a = b; return x; } void startupcpp() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } double distance(ddatas x, ddatas y) { double a, b; a = x.first - y.first; b = x.second - y.second; return sqrt(a * a + b * b); } ll modinv(ll a) { ll b = mod, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return (u + mod) % mod; } ll moddevide(ll a, ll b) { return (a * modinv(b)) % mod; } vec modncrlistp, modncrlistm; ll modncr(ll n, ll r) { ll i, size = modncrlistp.size(); if (size <= n) { modncrlistp.resize(n + 1); modncrlistm.resize(n + 1); if (!size) { modncrlistp[0] = modncrlistm[0] = 1; size++; } For(i, size, n + 1) { modncrlistp[i] = modncrlistp[i - 1] * i % mod; modncrlistm[i] = modinv(modncrlistp[i]); } } return modncrlistp[n] * modncrlistm[r] % mod * modncrlistm[n - r] % mod; } ll modpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll gcd(ll a, ll b) { if (!b) return a; return (a % b == 0) ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll countdigits(ll n) { ll ans = 0; while (n) { n /= 10; ans++; } return ans; } ll sumdigits(ll n) { ll ans = 0; while (n) { ans += n % 10; n /= 10; } return ans; } struct segtree { ll N, E; using func = function<ll(ll, ll)>; func f; vec tree; segtree(vec &v, ll e, func F) : E(e), f(F) { ll i, K = v.size(); N = 1; while (N < K) N *= 2; tree.resize(2 * N - 1); For(i, N - 1, N - 1 + K) tree[i] = v[i - N + 1]; For(i, N + K - 1, 2 * N - 1) tree[i] = E; brep(i, N - 1) tree[i] = f(tree[i * 2 + 1], tree[i * 2 + 2]); } void input(ll i, ll a) { i += N - 1; tree[i] = a; while (i) { i = (i - 1) / 2; tree[i] = f(tree[i * 2 + 1], tree[i * 2 + 2]); } } ll res(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return E; if (a <= l && r <= b) return tree[k]; return f(res(a, b, 2 * k + 1, l, (l + r) / 2), res(a, b, 2 * k + 2, (l + r) / 2, r)); } ll q(ll a, ll b) { return res(a, b, 0, 0, N); } void prt() { output(tree); } }; struct unionfind { vec par, treesize; unionfind(ll N) : par(N) { ll i; rep(i, N) par[i] = i; treesize.resize(N, 1); } ll root(ll x) { ll r; if (par[x] == x) return x; r = root(par[x]); if (par[x] != r) { treesize[r] += treesize[x]; treesize[x] = 0; par[x] = r; } return r; } bool unite(ll x, ll y) { ll px = root(x); ll py = root(y); if (px != py) { par[px] = py; treesize[py] += treesize[px]; treesize[px] = 0; } return px != py; } bool parcheck(ll x, ll y) { ll px = root(x); ll py = root(y); return px == py; } ll size(ll x) { ll px = root(x); return treesize[px]; } void clear() { ll i; rep(i, (ll)par.size()) { par[i] = i; treesize[i] = 1; } } }; int main() { startupcpp(); // ll test;cin>>test;while(test--){ ll i, j, k, N, M, K, f, cnt; cin >> N >> K; vector<double> x(N), y(N), c(N), r(N); rep(i, N) cin >> x[i] >> y[i] >> c[i]; double ans = 10000000, ng = 0, mid; while (ans - ng > eps) { mid = (ans + ng) / 2; f = 0; rep(i, N) r[i] = mid / c[i]; rep(i, N) { cnt = 1; rep(k, N) { if (i == k) continue; if (distance(ddatas(x[k], y[k]), ddatas(x[i], y[i])) <= r[k] + eps) cnt++; } if (cnt >= K) { f = 1; break; } For(j, i + 1, N) { if (distance(ddatas(x[i], y[i]), ddatas(x[j], y[j])) > r[i] + r[j] + eps) continue; double ansx, ansy, a, rot, kx, ky; kx = x[i] - x[j]; ky = y[i] - y[j]; a = kx * kx + ky * ky - r[i] * r[i] + r[j] * r[j]; a /= 2; rot = sqrt((kx * kx + ky * ky) * r[j] * r[j] - a * a); ansx = x[j] + (a * kx + ky * rot) / (kx * kx + ky * ky); ansy = y[j] + (a * ky - kx * rot) / (kx * kx + ky * ky); cnt = 2; rep(k, N) { if (i == k || j == k) continue; if (distance(ddatas(x[k], y[k]), ddatas(ansx, ansy)) <= r[k] + eps) cnt++; } if (cnt >= K) { i = N; f = 1; break; } ansx = x[j] + (a * kx - ky * rot) / (kx * kx + ky * ky); ansy = y[j] + (a * ky + kx * rot) / (kx * kx + ky * ky); cnt = 2; rep(k, N) { if (i == k || j == k) continue; if (distance(ddatas(x[k], y[k]), ddatas(ansx, ansy)) <= r[k] + eps) cnt++; } if (cnt >= K) { i = N; f = 1; break; } } } if (f) { ans = mid; } else { ng = mid; } } print(ans); return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; using namespace std; using ll = long long; // #define double long double using datas = pair<ll, ll>; using ddatas = pair<double, double>; using tdata = pair<ll, datas>; using vec = vector<ll>; using mat = vector<vec>; using pvec = vector<datas>; using pmat = vector<pvec>; // using // llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>; #define For(i, a, b) for (i = a; i < (ll)b; i++) #define bFor(i, a, b) for (i = a; i >= (ll)b; i--) #define rep(i, N) For(i, 0, N) #define rep1(i, N) For(i, 1, N) #define brep(i, N) bFor(i, N - 1, 0) #define all(v) (v).begin(), (v).end() #define allr(v) (v).rbegin(), (v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define endl "\n" #define pb push_back #define eb emplace_back #define print(v) cout << v << endl #define printyes cout << "Yes" << endl #define printno cout << "No" << endl #define printYES cout << "YES" << endl #define printNO cout << "NO" << endl #define output(v) \ do { \ bool f = 0; \ for (auto outi : v) { \ cout << (f ? " " : "") << outi; \ f = 1; \ } \ cout << endl; \ } while (0) const ll mod = 1000000007; const ll inf = 1LL << 60; const double PI = acos(-1); const double eps = 1e-9; template <class T> inline bool chmax(T &a, T b) { bool x = a < b; if (x) a = b; return x; } template <class T> inline bool chmin(T &a, T b) { bool x = a > b; if (x) a = b; return x; } void startupcpp() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } double distance(ddatas x, ddatas y) { double a, b; a = x.first - y.first; b = x.second - y.second; return sqrt(a * a + b * b); } ll modinv(ll a) { ll b = mod, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return (u + mod) % mod; } ll moddevide(ll a, ll b) { return (a * modinv(b)) % mod; } vec modncrlistp, modncrlistm; ll modncr(ll n, ll r) { ll i, size = modncrlistp.size(); if (size <= n) { modncrlistp.resize(n + 1); modncrlistm.resize(n + 1); if (!size) { modncrlistp[0] = modncrlistm[0] = 1; size++; } For(i, size, n + 1) { modncrlistp[i] = modncrlistp[i - 1] * i % mod; modncrlistm[i] = modinv(modncrlistp[i]); } } return modncrlistp[n] * modncrlistm[r] % mod * modncrlistm[n - r] % mod; } ll modpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll gcd(ll a, ll b) { if (!b) return a; return (a % b == 0) ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll countdigits(ll n) { ll ans = 0; while (n) { n /= 10; ans++; } return ans; } ll sumdigits(ll n) { ll ans = 0; while (n) { ans += n % 10; n /= 10; } return ans; } struct segtree { ll N, E; using func = function<ll(ll, ll)>; func f; vec tree; segtree(vec &v, ll e, func F) : E(e), f(F) { ll i, K = v.size(); N = 1; while (N < K) N *= 2; tree.resize(2 * N - 1); For(i, N - 1, N - 1 + K) tree[i] = v[i - N + 1]; For(i, N + K - 1, 2 * N - 1) tree[i] = E; brep(i, N - 1) tree[i] = f(tree[i * 2 + 1], tree[i * 2 + 2]); } void input(ll i, ll a) { i += N - 1; tree[i] = a; while (i) { i = (i - 1) / 2; tree[i] = f(tree[i * 2 + 1], tree[i * 2 + 2]); } } ll res(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return E; if (a <= l && r <= b) return tree[k]; return f(res(a, b, 2 * k + 1, l, (l + r) / 2), res(a, b, 2 * k + 2, (l + r) / 2, r)); } ll q(ll a, ll b) { return res(a, b, 0, 0, N); } void prt() { output(tree); } }; struct unionfind { vec par, treesize; unionfind(ll N) : par(N) { ll i; rep(i, N) par[i] = i; treesize.resize(N, 1); } ll root(ll x) { ll r; if (par[x] == x) return x; r = root(par[x]); if (par[x] != r) { treesize[r] += treesize[x]; treesize[x] = 0; par[x] = r; } return r; } bool unite(ll x, ll y) { ll px = root(x); ll py = root(y); if (px != py) { par[px] = py; treesize[py] += treesize[px]; treesize[px] = 0; } return px != py; } bool parcheck(ll x, ll y) { ll px = root(x); ll py = root(y); return px == py; } ll size(ll x) { ll px = root(x); return treesize[px]; } void clear() { ll i; rep(i, (ll)par.size()) { par[i] = i; treesize[i] = 1; } } }; int main() { startupcpp(); // ll test;cin>>test;while(test--){ ll i, j, k, N, M, K, f, cnt; cin >> N >> K; vector<double> x(N), y(N), c(N), r(N); rep(i, N) cin >> x[i] >> y[i] >> c[i]; double ans = 10000000, ng = 0, mid; while (ans - ng > eps) { mid = (ans + ng) / 2; f = 0; rep(i, N) r[i] = mid / c[i]; rep(i, N) { cnt = 1; rep(k, N) { if (i == k) continue; if (distance(ddatas(x[k], y[k]), ddatas(x[i], y[i])) <= r[k] + eps) cnt++; } if (cnt >= K) { f = 1; break; } For(j, i + 1, N) { if (distance(ddatas(x[i], y[i]), ddatas(x[j], y[j])) > r[i] + r[j] + eps) continue; double ansx, ansy, a, rot, kx, ky; kx = x[i] - x[j]; ky = y[i] - y[j]; a = kx * kx + ky * ky - r[i] * r[i] + r[j] * r[j]; a /= 2; rot = sqrt((kx * kx + ky * ky) * r[j] * r[j] - a * a); ansx = x[j] + (a * kx + ky * rot) / (kx * kx + ky * ky); ansy = y[j] + (a * ky - kx * rot) / (kx * kx + ky * ky); cnt = 2; rep(k, N) { if (i == k || j == k) continue; if (distance(ddatas(x[k], y[k]), ddatas(ansx, ansy)) <= r[k] + eps) cnt++; } if (cnt >= K) { i = N; f = 1; break; } ansx = x[j] + (a * kx - ky * rot) / (kx * kx + ky * ky); ansy = y[j] + (a * ky + kx * rot) / (kx * kx + ky * ky); cnt = 2; rep(k, N) { if (i == k || j == k) continue; if (distance(ddatas(x[k], y[k]), ddatas(ansx, ansy)) <= r[k] + eps) cnt++; } if (cnt >= K) { i = N; f = 1; break; } } } if (f) { ans = mid; } else { ng = mid; } } print(ans); return 0; }
replace
8
9
8
9
TLE
p02764
C++
Runtime Error
#ifndef LOCAL #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native") #endif // LOCAL #define _SCL_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/STACK:256000000") // #define push_back pb #define first x #define second y #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <ciso646> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <forward_list> #include <fstream> #include <functional> #include <initializer_list> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #ifdef LOCAL // #include <vld.h> #endif // LOCAL using namespace std; // typedef __int128_t ll; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef long double ld; #define speedup \ cout.tie(nullptr); \ cin.tie(nullptr); \ ios_base::sync_with_stdio(false) #define coutdouble \ cout << setprecision(20); \ cout << fixed #define all(v) (v).begin(), (v).end() #define sz(v) (int)(v).size() #ifdef LOCAL mt19937 rd(57322); #else mt19937 rd((uint)chrono::steady_clock::now().time_since_epoch().count()); #endif /*------CommentInInteractive--------*/ #ifndef LOCAL #define endl '\n' #endif // LOCAL /*----------------------------------*/ const int INF = 1000 * 1000 * 1000 + 322; const ll LLINF = 2LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL + 57; constexpr uint MOD = 1000 * 1000 * 1000 + 7; constexpr uint FFT_MOD = 998244353; const int P1E6 = 1336337; const int P1E3 = 1009; const ll P1E14 = 100000000000031; const ll P1E17 = 100000000000000003; const ld PI = acosl(-1.); // 3.1415926535897932384626433832795 const ld EPS = 1e-6; /*------------------------------------------------IO_OPERATORS---------------------------------------------*/ template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; } template <typename T, typename U> inline istream &operator>>(istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template <typename T> inline ostream &operator<<(ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline istream &operator>>(istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; } template <typename T> inline ostream &operator<<(ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline ostream &operator<<(ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T, typename U> inline ostream &operator<<(ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; } template <typename T, typename U> inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; } /*--------------------------------------------------IO_FILES-----------------------------------------------*/ const char *infile = #ifdef LOCAL "input.txt" #else "" #endif // LOCAL ; const char *outfile = #ifdef LOCAL "" #else "" #endif // LOCAL ; /*-------------------------------------------------ALLOCATOR----------------------------------------------*/ // #define ALLOC_LOCAL #ifdef ALLOC_LOCAL const int ML_ = 450; char mem_[ML_ * 1024 * 1024]; size_t _ptr = 0, _magic = 21323400; void *operator new(size_t cnt) { if (_ptr + cnt < sizeof mem_) { _ptr += cnt; return mem_ + _ptr - cnt; } else { assert(false); _ptr = cnt + _magic; return mem_ + _magic; } } void operator delete(void *) {} #endif // ALLOC_LOCAL /*-----------------------------------------------------MATH------------------------------------------------*/ inline ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline int pwm(ll xx, ll pow, int MD) { if (pow < 0) { pow = pow % (MD - 1) + MD - 1; } ll mlt = 1; while (pow) { if (pow & 1) { mlt *= xx; mlt %= MD; } xx *= xx; pow >>= 1; xx %= MD; } return (int)mlt; } inline ll gcdex(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll xx, yy; ll gc = gcdex(b, a % b, yy, xx); x = xx; y = yy - (a / b) * xx; return gc; } inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); } /*-----------------------------------------------------CODE------------------------------------------------*/ vector<ld> slvsq(const vector<ld> &cf) { assert(sz(cf) == 3); ld det = cf[1] * cf[1] - 4 * cf[0] * cf[2]; if (det < 0) { return {}; } return {(-cf[1] - sqrtl(det)) / (2 * cf[0]), (-cf[1] + sqrtl(det)) / (2 * cf[0])}; } ld get_t(const pair<pair<ll, ll>, ll> &pp, ld x, ld y) { return pp.y * hypotl(pp.x.x - x, pp.x.y - y); } ld checkpt(const vector<pair<pair<ll, ll>, ll>> &v, ld x, ld y, int k) { vector<ld> dsts; for (const auto &pp : v) { dsts.push_back(get_t(pp, x, y)); } nth_element(dsts.begin(), dsts.begin() + k - 1, dsts.end()); return dsts[k - 1]; } ld calc(const vector<pair<pair<ll, ll>, ll>> &v, int i, int j, int k, int need) { if (v[i].y == v[j].y && v[i].y == v[k].y) { ld a0 = 2 * (v[j].x.y * v[j].y * v[j].y - v[i].x.y * v[i].y * v[i].y); ld b0 = 2 * (v[j].x.x * v[j].y * v[j].y - v[i].x.x * v[i].y * v[i].y); ld c0 = (v[i].y * v[i].y * v[i].x.x * v[i].x.x + v[i].y * v[i].y * v[i].x.y * v[i].x.y - v[j].y * v[j].y * v[j].x.x * v[j].x.x - v[j].y * v[j].y * v[j].x.y * v[j].x.y); ld a1 = 2 * (v[k].x.y * v[k].y * v[k].y - v[j].x.y * v[j].y * v[j].y); ld b1 = 2 * (v[k].x.x * v[k].y * v[k].y - v[j].x.x * v[j].y * v[j].y); ld c1 = (v[j].y * v[j].y * v[j].x.x * v[j].x.x + v[j].y * v[j].y * v[j].x.y * v[j].x.y - v[k].y * v[k].y * v[k].x.x * v[k].x.x - v[k].y * v[k].y * v[k].x.y * v[k].x.y); if (abs(a0) < EPS && abs(a1) < EPS) { return INF; } if (abs(a0) < EPS) { swap(a0, a1); swap(b0, b1); swap(c0, c1); } b0 /= a0; c0 /= a0; a0 = 1; b1 -= a1 * b0; c1 -= a1 * c0; a1 = 0; if (abs(b1) < EPS) { return INF; } ld x = -c1 / b1; ld y = -b0 * x - c0; ld t1 = get_t(v[i], x, y); ld t2 = get_t(v[j], x, y); ld t3 = get_t(v[k], x, y); if (max(abs(t1 - t2), abs(t2 - t3)) > EPS) { while (true) { t1 += 1; } } return checkpt(v, x, y, need); } else if (v[i].y != v[j].y && v[i].y != v[k].y) { swap(i, j); } else if (v[k].y != v[j].y && v[i].y != v[k].y) { swap(j, k); } ld dv0 = v[i].y * v[i].y - v[j].y * v[j].y; assert(abs(dv0) > EPS); ld al0 = 2 * (v[j].x.y * v[j].y * v[j].y - v[i].x.y * v[i].y * v[i].y) / dv0; ld bt0 = 2 * (v[j].x.x * v[j].y * v[j].y - v[i].x.x * v[i].y * v[i].y) / dv0; ld gm0 = (v[i].y * v[i].y * v[i].x.x * v[i].x.x + v[i].y * v[i].y * v[i].x.y * v[i].x.y - v[j].y * v[j].y * v[j].x.x * v[j].x.x - v[j].y * v[j].y * v[j].x.y * v[j].x.y) / dv0; ld dv1 = v[j].y * v[j].y - v[k].y * v[k].y; assert(abs(dv1) > EPS); ld al1 = 2 * (v[k].x.y * v[k].y * v[k].y - v[j].x.y * v[j].y * v[j].y) / dv1; ld bt1 = 2 * (v[k].x.x * v[k].y * v[k].y - v[j].x.x * v[j].y * v[j].y) / dv1; ld gm1 = (v[j].y * v[j].y * v[j].x.x * v[j].x.x + v[j].y * v[j].y * v[j].x.y * v[j].x.y - v[k].y * v[k].y * v[k].x.x * v[k].x.x - v[k].y * v[k].y * v[k].x.y * v[k].x.y) / dv1; ld cf1 = al0 - al1; ld cf2 = bt0 - bt1; ld cf3 = gm0 - gm1; vector<pair<ld, ld>> tocheck; if (abs(cf1) > EPS) { ld kk = -cf2 / cf1; ld bb = -cf3 / cf1; vector<ld> quad = {kk * kk + 1, 2 * kk * bb + al0 * kk + bt0, gm0 + bb * bb + al0 * bb}; auto xx = slvsq(quad); for (auto &x : xx) { // cerr << quad[0] * x * x + quad[1] * x + quad[2] << endl; // assert(abs(quad[0] * x * x + quad[1] * x + quad[2]) < EPS); tocheck.push_back({x, kk * x + bb}); } } else if (abs(cf2) > EPS) { ld x = -cf3 / cf2; vector<ld> quad = {1, al0, bt0 * x + gm0 + x * x}; auto yy = slvsq(quad); for (auto &y : yy) { tocheck.push_back({x, y}); } } else { assert(abs(cf3) > EPS); } ld ans = INF; for (auto &p : tocheck) { ld x = p.x; ld y = p.y; ld t1 = get_t(v[i], x, y); ld t2 = get_t(v[j], x, y); ld t3 = get_t(v[k], x, y); if (max(abs(t1 - t2), abs(t2 - t3)) > EPS) { assert(false); } ans = min(ans, checkpt(v, x, y, need)); } return ans; } inline void solve() { int n, k; cin >> n >> k; vector<pair<pair<ll, ll>, ll>> v(n); cin >> v; if (k == 1) { cout << 0 << endl; return; } if (k == 2) { ld tt = INF; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ld dst = hypot(v[i].x.x - v[j].x.x, v[i].x.y - v[j].x.y); tt = min(tt, v[i].y * v[j].y * dst / (v[i].y + v[j].y)); } } cout << tt << endl; return; } ld tt = INF; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { for (int kk = j + 1; kk < n; ++kk) { tt = min(tt, calc(v, i, j, kk, k)); } } } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ld cf = ld(v[j].y) / (v[i].y + v[j].y); ld x = v[i].x.x + (v[j].x.x - v[i].x.x) * cf; ld y = v[i].x.y + (v[j].x.y - v[i].x.y) * cf; tt = min(tt, checkpt(v, x, y, k)); } } cout << tt << endl; } int main() { if (*infile != '\0') (void)freopen(infile, "r", stdin); if (*outfile != '\0') (void)freopen(outfile, "w", stdout); speedup; coutdouble; // int tst = 1; // srand(time(NULL)); // cin >> tst; // scanf("%d", &tst); // while (tst-- > 0) { // while(true) { solve(); // if ((tst & 0xF) == 0) { // cerr << "ok\n"; // } // cerr << "/*-----------------*/\n"; // } #ifdef LOCAL cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << endl; while (true) ; #endif // LOCAL return 0; }
#ifndef LOCAL #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native") #endif // LOCAL #define _SCL_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/STACK:256000000") // #define push_back pb #define first x #define second y #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <ciso646> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <forward_list> #include <fstream> #include <functional> #include <initializer_list> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #ifdef LOCAL // #include <vld.h> #endif // LOCAL using namespace std; // typedef __int128_t ll; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef long double ld; #define speedup \ cout.tie(nullptr); \ cin.tie(nullptr); \ ios_base::sync_with_stdio(false) #define coutdouble \ cout << setprecision(20); \ cout << fixed #define all(v) (v).begin(), (v).end() #define sz(v) (int)(v).size() #ifdef LOCAL mt19937 rd(57322); #else mt19937 rd((uint)chrono::steady_clock::now().time_since_epoch().count()); #endif /*------CommentInInteractive--------*/ #ifndef LOCAL #define endl '\n' #endif // LOCAL /*----------------------------------*/ const int INF = 1000 * 1000 * 1000 + 322; const ll LLINF = 2LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL + 57; constexpr uint MOD = 1000 * 1000 * 1000 + 7; constexpr uint FFT_MOD = 998244353; const int P1E6 = 1336337; const int P1E3 = 1009; const ll P1E14 = 100000000000031; const ll P1E17 = 100000000000000003; const ld PI = acosl(-1.); // 3.1415926535897932384626433832795 const ld EPS = 1e-6; /*------------------------------------------------IO_OPERATORS---------------------------------------------*/ template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; } template <typename T, typename U> inline istream &operator>>(istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template <typename T> inline ostream &operator<<(ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline istream &operator>>(istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; } template <typename T> inline ostream &operator<<(ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline ostream &operator<<(ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T> inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template <typename T, typename U> inline ostream &operator<<(ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; } template <typename T, typename U> inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; } /*--------------------------------------------------IO_FILES-----------------------------------------------*/ const char *infile = #ifdef LOCAL "input.txt" #else "" #endif // LOCAL ; const char *outfile = #ifdef LOCAL "" #else "" #endif // LOCAL ; /*-------------------------------------------------ALLOCATOR----------------------------------------------*/ // #define ALLOC_LOCAL #ifdef ALLOC_LOCAL const int ML_ = 450; char mem_[ML_ * 1024 * 1024]; size_t _ptr = 0, _magic = 21323400; void *operator new(size_t cnt) { if (_ptr + cnt < sizeof mem_) { _ptr += cnt; return mem_ + _ptr - cnt; } else { assert(false); _ptr = cnt + _magic; return mem_ + _magic; } } void operator delete(void *) {} #endif // ALLOC_LOCAL /*-----------------------------------------------------MATH------------------------------------------------*/ inline ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline int pwm(ll xx, ll pow, int MD) { if (pow < 0) { pow = pow % (MD - 1) + MD - 1; } ll mlt = 1; while (pow) { if (pow & 1) { mlt *= xx; mlt %= MD; } xx *= xx; pow >>= 1; xx %= MD; } return (int)mlt; } inline ll gcdex(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll xx, yy; ll gc = gcdex(b, a % b, yy, xx); x = xx; y = yy - (a / b) * xx; return gc; } inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); } /*-----------------------------------------------------CODE------------------------------------------------*/ vector<ld> slvsq(const vector<ld> &cf) { assert(sz(cf) == 3); ld det = cf[1] * cf[1] - 4 * cf[0] * cf[2]; if (det < 0) { return {}; } return {(-cf[1] - sqrtl(det)) / (2 * cf[0]), (-cf[1] + sqrtl(det)) / (2 * cf[0])}; } ld get_t(const pair<pair<ll, ll>, ll> &pp, ld x, ld y) { return pp.y * hypotl(pp.x.x - x, pp.x.y - y); } ld checkpt(const vector<pair<pair<ll, ll>, ll>> &v, ld x, ld y, int k) { vector<ld> dsts; for (const auto &pp : v) { dsts.push_back(get_t(pp, x, y)); } nth_element(dsts.begin(), dsts.begin() + k - 1, dsts.end()); return dsts[k - 1]; } ld calc(const vector<pair<pair<ll, ll>, ll>> &v, int i, int j, int k, int need) { if (v[i].y == v[j].y && v[i].y == v[k].y) { ld a0 = 2 * (v[j].x.y * v[j].y * v[j].y - v[i].x.y * v[i].y * v[i].y); ld b0 = 2 * (v[j].x.x * v[j].y * v[j].y - v[i].x.x * v[i].y * v[i].y); ld c0 = (v[i].y * v[i].y * v[i].x.x * v[i].x.x + v[i].y * v[i].y * v[i].x.y * v[i].x.y - v[j].y * v[j].y * v[j].x.x * v[j].x.x - v[j].y * v[j].y * v[j].x.y * v[j].x.y); ld a1 = 2 * (v[k].x.y * v[k].y * v[k].y - v[j].x.y * v[j].y * v[j].y); ld b1 = 2 * (v[k].x.x * v[k].y * v[k].y - v[j].x.x * v[j].y * v[j].y); ld c1 = (v[j].y * v[j].y * v[j].x.x * v[j].x.x + v[j].y * v[j].y * v[j].x.y * v[j].x.y - v[k].y * v[k].y * v[k].x.x * v[k].x.x - v[k].y * v[k].y * v[k].x.y * v[k].x.y); if (abs(a0) < EPS && abs(a1) < EPS) { return INF; } if (abs(a0) < EPS) { swap(a0, a1); swap(b0, b1); swap(c0, c1); } b0 /= a0; c0 /= a0; a0 = 1; b1 -= a1 * b0; c1 -= a1 * c0; a1 = 0; if (abs(b1) < EPS) { return INF; } ld x = -c1 / b1; ld y = -b0 * x - c0; ld t1 = get_t(v[i], x, y); ld t2 = get_t(v[j], x, y); ld t3 = get_t(v[k], x, y); if (max(abs(t1 - t2), abs(t2 - t3)) > EPS) { while (true) { t1 += 1; } } return checkpt(v, x, y, need); } else if (v[i].y != v[j].y && v[i].y != v[k].y) { swap(i, j); } else if (v[k].y != v[j].y && v[i].y != v[k].y) { swap(j, k); } ld dv0 = v[i].y * v[i].y - v[j].y * v[j].y; assert(abs(dv0) > EPS); ld al0 = 2 * (v[j].x.y * v[j].y * v[j].y - v[i].x.y * v[i].y * v[i].y) / dv0; ld bt0 = 2 * (v[j].x.x * v[j].y * v[j].y - v[i].x.x * v[i].y * v[i].y) / dv0; ld gm0 = (v[i].y * v[i].y * v[i].x.x * v[i].x.x + v[i].y * v[i].y * v[i].x.y * v[i].x.y - v[j].y * v[j].y * v[j].x.x * v[j].x.x - v[j].y * v[j].y * v[j].x.y * v[j].x.y) / dv0; ld dv1 = v[j].y * v[j].y - v[k].y * v[k].y; assert(abs(dv1) > EPS); ld al1 = 2 * (v[k].x.y * v[k].y * v[k].y - v[j].x.y * v[j].y * v[j].y) / dv1; ld bt1 = 2 * (v[k].x.x * v[k].y * v[k].y - v[j].x.x * v[j].y * v[j].y) / dv1; ld gm1 = (v[j].y * v[j].y * v[j].x.x * v[j].x.x + v[j].y * v[j].y * v[j].x.y * v[j].x.y - v[k].y * v[k].y * v[k].x.x * v[k].x.x - v[k].y * v[k].y * v[k].x.y * v[k].x.y) / dv1; ld cf1 = al0 - al1; ld cf2 = bt0 - bt1; ld cf3 = gm0 - gm1; vector<pair<ld, ld>> tocheck; if (abs(cf1) > EPS) { ld kk = -cf2 / cf1; ld bb = -cf3 / cf1; vector<ld> quad = {kk * kk + 1, 2 * kk * bb + al0 * kk + bt0, gm0 + bb * bb + al0 * bb}; auto xx = slvsq(quad); for (auto &x : xx) { // cerr << quad[0] * x * x + quad[1] * x + quad[2] << endl; // assert(abs(quad[0] * x * x + quad[1] * x + quad[2]) < EPS); tocheck.push_back({x, kk * x + bb}); } } else if (abs(cf2) > EPS) { ld x = -cf3 / cf2; vector<ld> quad = {1, al0, bt0 * x + gm0 + x * x}; auto yy = slvsq(quad); for (auto &y : yy) { tocheck.push_back({x, y}); } } else { assert(abs(cf3) > EPS); } ld ans = INF; for (auto &p : tocheck) { ld x = p.x; ld y = p.y; ld t1 = get_t(v[i], x, y); ld t2 = get_t(v[j], x, y); ld t3 = get_t(v[k], x, y); // if (max(abs(t1 - t2), abs(t2 - t3)) > EPS) { // assert(false); // } ans = min(ans, checkpt(v, x, y, need)); } return ans; } inline void solve() { int n, k; cin >> n >> k; vector<pair<pair<ll, ll>, ll>> v(n); cin >> v; if (k == 1) { cout << 0 << endl; return; } if (k == 2) { ld tt = INF; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ld dst = hypot(v[i].x.x - v[j].x.x, v[i].x.y - v[j].x.y); tt = min(tt, v[i].y * v[j].y * dst / (v[i].y + v[j].y)); } } cout << tt << endl; return; } ld tt = INF; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { for (int kk = j + 1; kk < n; ++kk) { tt = min(tt, calc(v, i, j, kk, k)); } } } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ld cf = ld(v[j].y) / (v[i].y + v[j].y); ld x = v[i].x.x + (v[j].x.x - v[i].x.x) * cf; ld y = v[i].x.y + (v[j].x.y - v[i].x.y) * cf; tt = min(tt, checkpt(v, x, y, k)); } } cout << tt << endl; } int main() { if (*infile != '\0') (void)freopen(infile, "r", stdin); if (*outfile != '\0') (void)freopen(outfile, "w", stdout); speedup; coutdouble; // int tst = 1; // srand(time(NULL)); // cin >> tst; // scanf("%d", &tst); // while (tst-- > 0) { // while(true) { solve(); // if ((tst & 0xF) == 0) { // cerr << "ok\n"; // } // cerr << "/*-----------------*/\n"; // } #ifdef LOCAL cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << endl; while (true) ; #endif // LOCAL return 0; }
replace
381
384
381
384
0
p02764
C++
Runtime Error
#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323846 void *wmem; char memarr[96000000]; template <class T> inline void walloc1d(T **arr, int x, void **mem = &wmem) { static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void *)(((char *)(*mem)) + skip[((unsigned long long)(*mem)) & 15]); (*arr) = (T *)(*mem); (*mem) = ((*arr) + x); } template <class T1> void sortA_L(int N, T1 a[], void *mem = wmem) { sort(a, a + N); } inline void rd(int &x) { int k; int m = 0; x = 0; for (;;) { k = getchar_unlocked(); if (k == '-') { m = 1; break; } if ('0' <= k && k <= '9') { x = k - '0'; break; } } for (;;) { k = getchar_unlocked(); if (k < '0' || k > '9') { break; } x = x * 10 + k - '0'; } if (m) { x = -x; } } inline void rd(double &x) { scanf("%lf", &x); } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(double x) { printf("%.15f", x); } template <class T> inline T pow2_L(T a) { return a * a; } template <class S, class T> inline S chmin(S &a, T b) { if (a > b) { a = b; } return a; } #define EPS 1e-10 int N; int K; double X[60]; double Y[60]; int C[60]; struct pnt { double x; double y; }; struct line { pnt a; pnt b; }; struct circle { pnt c; double r; }; pnt p[60]; int doubleSign(double a) { if (a > EPS) { return 1; } if (a < -EPS) { return -1; } return 0; } int doubleSignR(double a, double b) { if (doubleSign(b) != 0 && doubleSign(a / b - 1) == 0) { return 0; } return doubleSign(a - b); } int pntSign(pnt a) { int i = doubleSign(a.x); if (i) { return i; } return doubleSign(a.y); } pnt pntPlus(pnt a, pnt b) { a.x += b.x; a.y += b.y; return a; } pnt pntMinus(pnt a, pnt b) { a.x -= b.x; a.y -= b.y; return a; } pnt pntMultiple(pnt a, pnt b) { pnt c; c.x = a.x * b.x - a.y * b.y; c.y = a.x * b.y + a.y * b.x; return c; } pnt pntMultipleDouble(pnt a, double k) { a.x *= k; a.y *= k; return a; } pnt pntPolar(double r, double t) { pnt a; a.x = r * cos(t); a.y = r * sin(t); return a; } int pntIsEqual(pnt a, pnt b) { return pntSign(pntMinus(a, b)) == 0; } pnt pntRatation(pnt a, pnt o, double t) { return pntPlus(pntMultiple(pntMinus(a, o), pntPolar(1.0, t)), o); } pnt pntRatationEasy(pnt a, double t) { return pntMultiple(a, pntPolar(1.0, t)); } line perpendicularBisectorOfSegment(pnt a, pnt b) { line res; pnt mid; pnt dir; mid = pntMultipleDouble(pntPlus(a, b), 0.5); dir = pntRatationEasy(pntMinus(b, a), PI / 2); res.a = pntMinus(mid, dir); res.b = pntPlus(mid, dir); return res; } int doubleSolveSecondDegreeEquation(double a, double b, double c, double *res1, double *res2) { if (doubleSign(a)) { double d = b * b - 4 * a * c; int m = doubleSign(d) + 1; if (m == 1) { *res1 = -b / (2 * a); } if (m == 2) { d = sqrt(d); *res1 = (-b - d) / (2 * a); *res2 = (-b + d) / (2 * a); } return m; } if (doubleSign(b)) { *res1 = -b / c; return 1; } if (doubleSign(c)) { return 0; } return 3; } int pntIntersectionLineCircle(line t, circle s, pnt *res1, pnt *res2) { int m; double a; double b; double c; double t1; double t2; double k1; double k2; pnt ab = pntMinus(t.b, t.a); a = b = 0; c = -s.r * s.r; t1 = t.a.x - s.c.x; t2 = t.b.x - t.a.x; a += t2 * t2; b += 2 * t1 * t2; c += t1 * t1; t1 = t.a.y - s.c.y; t2 = t.b.y - t.a.y; a += t2 * t2; b += 2 * t1 * t2; c += t1 * t1; m = doubleSolveSecondDegreeEquation(a, b, c, &k1, &k2); if (m >= 1) { *res1 = pntPlus(t.a, pntMultipleDouble(ab, k1)); } if (m >= 2) { *res2 = pntPlus(t.a, pntMultipleDouble(ab, k2)); } return m; } line pntGetLineFromCoefficient(double a, double b, double c) { line res; if (doubleSign(a) == 0) { res.a.x = 0; res.b.x = 1; res.a.y = res.b.y = -c / b; } else { res.a.y = 0; res.b.y = 1; res.a.x = -c / a; res.b.x = (-b - c) / a; } return res; } int pntIntersectionCircleCircle(circle s1, circle s2, pnt *res1, pnt *res2) { double a; double b; double c; line t; double x1 = s1.c.x; double x2 = s2.c.x; double y1 = s1.c.y; double y2 = s2.c.y; double r1 = s1.r; double r2 = s2.r; if (pntIsEqual(s1.c, s2.c)) { if (doubleSign(s1.r - s2.r) == 0) { return 3; } return 0; } a = 2 * (x1 - x2); b = 2 * (y1 - y2); c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1) - (r2 * r2 - r1 * r1); t = pntGetLineFromCoefficient(a, b, c); return pntIntersectionLineCircle(t, s1, res1, res2); } int pntIntersectionLineLine(line s, line t, pnt *res) { pnt p1 = s.a; pnt p2 = s.b; pnt p3 = t.a; pnt p4 = t.b; double r = (p4.y - p3.y) * (p2.x - p1.x) - (p2.y - p1.y) * (p4.x - p3.x); if (doubleSign(r) == 0) { return 0; } res->x = (p3.x * p4.y - p3.y * p4.x) * (p2.x - p1.x) - (p1.x * p2.y - p1.y * p2.x) * (p4.x - p3.x); res->y = (p3.y * p4.x - p3.x * p4.y) * (p2.y - p1.y) - (p1.y * p2.x - p1.x * p2.y) * (p4.y - p3.y); res->x /= r; res->y /= -r; return 1; } int cs; int ls; circle c[4000]; line l[4000]; double arr[60]; double eval(double x, double y) { int i; for (i = (0); i < (N); i++) { arr[i] = C[i] * sqrt(pow2_L((X[i] - x)) + pow2_L((Y[i] - y))); } sortA_L(N, arr); return arr[K - 1]; } int main() { int i; wmem = memarr; int k; double x; double y; double x1; double y1; double x2; double y2; double res = 1e150; pnt p1; pnt p2; rd(N); rd(K); { int Q5VJL1cS; for (Q5VJL1cS = (0); Q5VJL1cS < (N); Q5VJL1cS++) { rd(X[Q5VJL1cS]); rd(Y[Q5VJL1cS]); rd(C[Q5VJL1cS]); } } for (i = (0); i < (N); i++) { p[i].x = X[i]; p[i].y = Y[i]; } for (i = (0); i < (N); i++) { chmin(res, eval(X[i], Y[i])); } for (i = (0); i < (N); i++) { int j; for (j = (i + 1); j < (N); j++) { x = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); y = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); chmin(res, eval(x, y)); } } for (i = (0); i < (N); i++) { int j; for (j = (i + 1); j < (N); j++) { if (C[i] == C[j]) { l[ls++] = perpendicularBisectorOfSegment(p[i], p[j]); } else { x1 = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); y1 = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); x2 = (C[i] * X[i] - C[j] * X[j]) / (C[i] - C[j]); y2 = (C[i] * Y[i] - C[j] * Y[j]) / (C[i] - C[j]); c[cs].c.x = (x1 + x2) / 2; c[cs].c.y = (y1 + y2) / 2; c[cs++].r = sqrt(pow2_L((x1 - x2)) + pow2_L((y1 - y2))) / 2; } } } for (i = (0); i < (cs); i++) { int j; for (j = (i + 1); j < (cs); j++) { k = pntIntersectionCircleCircle(c[i], c[j], &p1, &p2); if (k >= 1) { chmin(res, eval(p1.x, p1.y)); } if (k >= 2) { chmin(res, eval(p2.x, p2.y)); } } } for (i = (0); i < (ls); i++) { int j; for (j = (i + 1); j < (ls); j++) { k = pntIntersectionLineLine(l[i], l[j], &p1); if (k == 1) { chmin(res, eval(p1.x, p1.y)); } } } for (i = (0); i < (ls); i++) { int j; for (j = (0); j < (cs); j++) { k = pntIntersectionLineCircle(l[i], c[j], &p1, &p2); if (k >= 1) { chmin(res, eval(p1.x, p1.y)); } if (k >= 2) { chmin(res, eval(p2.x, p2.y)); } } } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20200227-1 // --- original code --- // #define EPS 1e-10 // // int N, K; // double X[60], Y[60]; int C[60]; // // struct pnt{double x,y;}; // struct line{pnt a,b;}; // struct circle{pnt c; double r;}; // // pnt p[60]; // // // int doubleSign(double a){if(a>EPS) return 1; if(a<-EPS) return -1; return 0;} // int doubleSignR(double a,double b){ if(doubleSign(b)!=0 && // doubleSign(a/b-1)==0) return 0; return doubleSign(a-b);} int pntSign(pnt // a){int i=doubleSign(a.x); if(i) return i; return doubleSign(a.y);} // // pnt pntPlus(pnt a,pnt b){a.x+=b.x; a.y+=b.y; return a;} // pnt pntMinus(pnt a,pnt b){a.x-=b.x; a.y-=b.y; return a;} // pnt pntMultiple(pnt a,pnt b){pnt c; c.x=a.x*b.x-a.y*b.y; c.y=a.x*b.y+a.y*b.x; // return c;} pnt pntMultipleDouble(pnt a,double k){a.x*=k; a.y*=k; return a;} // pnt pntPolar(double r,double t){pnt a; a.x=r*cos(t); a.y=r*sin(t); return a;} // // int pntIsEqual(pnt a,pnt b){return pntSign(pntMinus(a,b))==0;} // // pnt pntRatation(pnt a,pnt o,double t){ // return pntPlus(pntMultiple(pntMinus(a,o),pntPolar(1.0,t)),o); // } // // pnt pntRatationEasy(pnt a,double t){ // return pntMultiple(a,pntPolar(1.0,t)); // } // // // line perpendicularBisectorOfSegment(pnt a, pnt b){ // line res; pnt mid, dir; // mid = pntMultipleDouble(pntPlus(a,b),0.5); // dir = pntRatationEasy( pntMinus(b,a), PI/2 ); // res.a = pntMinus(mid,dir); res.b = pntPlus(mid,dir); // return res; // } // // int doubleSolveSecondDegreeEquation(double a,double b,double c,double // *res1,double *res2){ // if(doubleSign(a)){ // double d=b*b-4*a*c; int m=doubleSign(d)+1; // if(m==1) *res1=-b/(2*a); // if(m==2){d=sqrt(d); *res1=(-b-d)/(2*a); *res2=(-b+d)/(2*a);} // return m; // } // if(doubleSign(b)){*res1 = -b/c; return 1;} // if(doubleSign(c)) return 0; return 3; // } // // int pntIntersectionLineCircle(line t,circle s,pnt *res1,pnt *res2){ // int m; double a,b,c,t1,t2,k1,k2; pnt ab=pntMinus(t.b, t.a); // a=b=0; c=-s.r*s.r; // t1=t.a.x-s.c.x; t2=t.b.x-t.a.x; a+=t2*t2; b+=2*t1*t2; c+=t1*t1; // t1=t.a.y-s.c.y; t2=t.b.y-t.a.y; a+=t2*t2; b+=2*t1*t2; c+=t1*t1; // m=doubleSolveSecondDegreeEquation(a,b,c,&k1,&k2); // if(m>=1) *res1 = pntPlus( t.a, pntMultipleDouble(ab,k1) ); // if(m>=2) *res2 = pntPlus( t.a, pntMultipleDouble(ab,k2) ); // return m; // } // // line pntGetLineFromCoefficient(double a,double b,double c){ // line res; // if( doubleSign(a)==0 ){ // res.a.x = 0; res.b.x = 1; // res.a.y = res.b.y = -c/b; // } else { // res.a.y=0; res.b.y=1; // res.a.x=-c/a; res.b.x=(-b-c)/a; // } // return res; // } // // int pntIntersectionCircleCircle(circle s1,circle s2,pnt *res1,pnt *res2){ // double a,b,c; line t; // double x1=s1.c.x, x2=s2.c.x, y1=s1.c.y, y2=s2.c.y, r1=s1.r, r2=s2.r; // if( pntIsEqual(s1.c,s2.c) ){ if( doubleSign(s1.r-s2.r)==0 ) return 3; // return 0; } a = 2*(x1-x2); b = 2*(y1-y2); c = (x2*x2-x1*x1) + (y2*y2-y1*y1) // - (r2*r2-r1*r1); t = pntGetLineFromCoefficient(a,b,c); return // pntIntersectionLineCircle(t,s1,res1,res2); // } // // int pntIntersectionLineLine(line s,line t,pnt *res){ // pnt p1=s.a, p2=s.b, p3=t.a, p4=t.b; // double r = (p4.y-p3.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p4.x-p3.x); // if( doubleSign(r)==0 ) return 0; // res->x = // (p3.x*p4.y-p3.y*p4.x)*(p2.x-p1.x)-(p1.x*p2.y-p1.y*p2.x)*(p4.x-p3.x); res->y // = (p3.y*p4.x-p3.x*p4.y)*(p2.y-p1.y)-(p1.y*p2.x-p1.x*p2.y)*(p4.y-p3.y); // res->x /= r; res->y /= -r; return 1; // } // // // int cs; // int ls; // circle c[4000]; // line l[4000]; // // double arr[60]; // double eval(double x, double y){ // rep(i,N) arr[i] = C[i] * sqrt( (X[i]-x)**2 + (Y[i]-y)**2 ); // sortA(N,arr); // return arr[K-1]; // } // // { // int k; // double x, y, x1, y1, x2, y2; // double res = double_inf; // pnt p1; // pnt p2; // rd(N,K,(X,Y,C)(N)); // // rep(i,N) p[i].x = X[i], p[i].y = Y[i]; // // rep(i,N) res <?= eval(X[i], Y[i]); // rep(i,N) rep(j,i+1,N){ // x = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); // y = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); // res <?= eval(x, y); // } // // rep(i,N) rep(j,i+1,N){ // if(C[i] == C[j]){ // l[ls++] = perpendicularBisectorOfSegment(p[i], p[j]); // } else { // x1 = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); // y1 = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); // x2 = (C[i] * X[i] - C[j] * X[j]) / (C[i] - C[j]); // y2 = (C[i] * Y[i] - C[j] * Y[j]) / (C[i] - C[j]); // c[cs].c.x = (x1 + x2) / 2; // c[cs].c.y = (y1 + y2) / 2; // c[cs++].r = sqrt( (x1-x2)**2 + (y1-y2)**2 ) / 2; // } // } // // rep(i,cs) rep(j,i+1,cs){ // k = pntIntersectionCircleCircle(c[i],c[j],&p1,&p2); // if(k>=1) res <?= eval(p1.x, p1.y); // if(k>=2) res <?= eval(p2.x, p2.y); // } // // rep(i,ls) rep(j,i+1,ls){ // k = pntIntersectionLineLine(l[i], l[j], &p1); // if(k==1) res <?= eval(p1.x, p1.y); // } // // rep(i,ls) rep(j,cs){ // k = pntIntersectionLineCircle(l[i],c[j],&p1,&p2); // if(k>=1) res <?= eval(p1.x, p1.y); // if(k>=2) res <?= eval(p2.x, p2.y); // } // // wt(res); // }
#pragma GCC optimize("Ofast") #pragma GCC target("avx") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323846 void *wmem; char memarr[96000000]; template <class T> inline void walloc1d(T **arr, int x, void **mem = &wmem) { static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void *)(((char *)(*mem)) + skip[((unsigned long long)(*mem)) & 15]); (*arr) = (T *)(*mem); (*mem) = ((*arr) + x); } template <class T1> void sortA_L(int N, T1 a[], void *mem = wmem) { sort(a, a + N); } inline void rd(int &x) { int k; int m = 0; x = 0; for (;;) { k = getchar_unlocked(); if (k == '-') { m = 1; break; } if ('0' <= k && k <= '9') { x = k - '0'; break; } } for (;;) { k = getchar_unlocked(); if (k < '0' || k > '9') { break; } x = x * 10 + k - '0'; } if (m) { x = -x; } } inline void rd(double &x) { scanf("%lf", &x); } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(double x) { printf("%.15f", x); } template <class T> inline T pow2_L(T a) { return a * a; } template <class S, class T> inline S chmin(S &a, T b) { if (a > b) { a = b; } return a; } #define EPS 1e-10 int N; int K; double X[60]; double Y[60]; int C[60]; struct pnt { double x; double y; }; struct line { pnt a; pnt b; }; struct circle { pnt c; double r; }; pnt p[60]; int doubleSign(double a) { if (a > EPS) { return 1; } if (a < -EPS) { return -1; } return 0; } int doubleSignR(double a, double b) { if (doubleSign(b) != 0 && doubleSign(a / b - 1) == 0) { return 0; } return doubleSign(a - b); } int pntSign(pnt a) { int i = doubleSign(a.x); if (i) { return i; } return doubleSign(a.y); } pnt pntPlus(pnt a, pnt b) { a.x += b.x; a.y += b.y; return a; } pnt pntMinus(pnt a, pnt b) { a.x -= b.x; a.y -= b.y; return a; } pnt pntMultiple(pnt a, pnt b) { pnt c; c.x = a.x * b.x - a.y * b.y; c.y = a.x * b.y + a.y * b.x; return c; } pnt pntMultipleDouble(pnt a, double k) { a.x *= k; a.y *= k; return a; } pnt pntPolar(double r, double t) { pnt a; a.x = r * cos(t); a.y = r * sin(t); return a; } int pntIsEqual(pnt a, pnt b) { return pntSign(pntMinus(a, b)) == 0; } pnt pntRatation(pnt a, pnt o, double t) { return pntPlus(pntMultiple(pntMinus(a, o), pntPolar(1.0, t)), o); } pnt pntRatationEasy(pnt a, double t) { return pntMultiple(a, pntPolar(1.0, t)); } line perpendicularBisectorOfSegment(pnt a, pnt b) { line res; pnt mid; pnt dir; mid = pntMultipleDouble(pntPlus(a, b), 0.5); dir = pntRatationEasy(pntMinus(b, a), PI / 2); res.a = pntMinus(mid, dir); res.b = pntPlus(mid, dir); return res; } int doubleSolveSecondDegreeEquation(double a, double b, double c, double *res1, double *res2) { if (doubleSign(a)) { double d = b * b - 4 * a * c; int m = doubleSign(d) + 1; if (m == 1) { *res1 = -b / (2 * a); } if (m == 2) { d = sqrt(d); *res1 = (-b - d) / (2 * a); *res2 = (-b + d) / (2 * a); } return m; } if (doubleSign(b)) { *res1 = -b / c; return 1; } if (doubleSign(c)) { return 0; } return 3; } int pntIntersectionLineCircle(line t, circle s, pnt *res1, pnt *res2) { int m; double a; double b; double c; double t1; double t2; double k1; double k2; pnt ab = pntMinus(t.b, t.a); a = b = 0; c = -s.r * s.r; t1 = t.a.x - s.c.x; t2 = t.b.x - t.a.x; a += t2 * t2; b += 2 * t1 * t2; c += t1 * t1; t1 = t.a.y - s.c.y; t2 = t.b.y - t.a.y; a += t2 * t2; b += 2 * t1 * t2; c += t1 * t1; m = doubleSolveSecondDegreeEquation(a, b, c, &k1, &k2); if (m >= 1) { *res1 = pntPlus(t.a, pntMultipleDouble(ab, k1)); } if (m >= 2) { *res2 = pntPlus(t.a, pntMultipleDouble(ab, k2)); } return m; } line pntGetLineFromCoefficient(double a, double b, double c) { line res; if (doubleSign(a) == 0) { res.a.x = 0; res.b.x = 1; res.a.y = res.b.y = -c / b; } else { res.a.y = 0; res.b.y = 1; res.a.x = -c / a; res.b.x = (-b - c) / a; } return res; } int pntIntersectionCircleCircle(circle s1, circle s2, pnt *res1, pnt *res2) { double a; double b; double c; line t; double x1 = s1.c.x; double x2 = s2.c.x; double y1 = s1.c.y; double y2 = s2.c.y; double r1 = s1.r; double r2 = s2.r; if (pntIsEqual(s1.c, s2.c)) { if (doubleSign(s1.r - s2.r) == 0) { return 3; } return 0; } a = 2 * (x1 - x2); b = 2 * (y1 - y2); c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1) - (r2 * r2 - r1 * r1); t = pntGetLineFromCoefficient(a, b, c); return pntIntersectionLineCircle(t, s1, res1, res2); } int pntIntersectionLineLine(line s, line t, pnt *res) { pnt p1 = s.a; pnt p2 = s.b; pnt p3 = t.a; pnt p4 = t.b; double r = (p4.y - p3.y) * (p2.x - p1.x) - (p2.y - p1.y) * (p4.x - p3.x); if (doubleSign(r) == 0) { return 0; } res->x = (p3.x * p4.y - p3.y * p4.x) * (p2.x - p1.x) - (p1.x * p2.y - p1.y * p2.x) * (p4.x - p3.x); res->y = (p3.y * p4.x - p3.x * p4.y) * (p2.y - p1.y) - (p1.y * p2.x - p1.x * p2.y) * (p4.y - p3.y); res->x /= r; res->y /= -r; return 1; } int cs; int ls; circle c[4000]; line l[4000]; double arr[60]; double eval(double x, double y) { int i; for (i = (0); i < (N); i++) { arr[i] = C[i] * sqrt(pow2_L((X[i] - x)) + pow2_L((Y[i] - y))); } sortA_L(N, arr); return arr[K - 1]; } int main() { int i; wmem = memarr; int k; double x; double y; double x1; double y1; double x2; double y2; double res = 1e150; pnt p1; pnt p2; rd(N); rd(K); { int Q5VJL1cS; for (Q5VJL1cS = (0); Q5VJL1cS < (N); Q5VJL1cS++) { rd(X[Q5VJL1cS]); rd(Y[Q5VJL1cS]); rd(C[Q5VJL1cS]); } } for (i = (0); i < (N); i++) { p[i].x = X[i]; p[i].y = Y[i]; } for (i = (0); i < (N); i++) { chmin(res, eval(X[i], Y[i])); } for (i = (0); i < (N); i++) { int j; for (j = (i + 1); j < (N); j++) { x = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); y = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); chmin(res, eval(x, y)); } } for (i = (0); i < (N); i++) { int j; for (j = (i + 1); j < (N); j++) { if (C[i] == C[j]) { l[ls++] = perpendicularBisectorOfSegment(p[i], p[j]); } else { x1 = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); y1 = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); x2 = (C[i] * X[i] - C[j] * X[j]) / (C[i] - C[j]); y2 = (C[i] * Y[i] - C[j] * Y[j]) / (C[i] - C[j]); c[cs].c.x = (x1 + x2) / 2; c[cs].c.y = (y1 + y2) / 2; c[cs++].r = sqrt(pow2_L((x1 - x2)) + pow2_L((y1 - y2))) / 2; } } } for (i = (0); i < (cs); i++) { int j; for (j = (i + 1); j < (cs); j++) { k = pntIntersectionCircleCircle(c[i], c[j], &p1, &p2); if (k >= 1) { chmin(res, eval(p1.x, p1.y)); } if (k >= 2) { chmin(res, eval(p2.x, p2.y)); } } } for (i = (0); i < (ls); i++) { int j; for (j = (i + 1); j < (ls); j++) { k = pntIntersectionLineLine(l[i], l[j], &p1); if (k == 1) { chmin(res, eval(p1.x, p1.y)); } } } for (i = (0); i < (ls); i++) { int j; for (j = (0); j < (cs); j++) { k = pntIntersectionLineCircle(l[i], c[j], &p1, &p2); if (k >= 1) { chmin(res, eval(p1.x, p1.y)); } if (k >= 2) { chmin(res, eval(p2.x, p2.y)); } } } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20200227-1 // --- original code --- // #define EPS 1e-10 // // int N, K; // double X[60], Y[60]; int C[60]; // // struct pnt{double x,y;}; // struct line{pnt a,b;}; // struct circle{pnt c; double r;}; // // pnt p[60]; // // // int doubleSign(double a){if(a>EPS) return 1; if(a<-EPS) return -1; return 0;} // int doubleSignR(double a,double b){ if(doubleSign(b)!=0 && // doubleSign(a/b-1)==0) return 0; return doubleSign(a-b);} int pntSign(pnt // a){int i=doubleSign(a.x); if(i) return i; return doubleSign(a.y);} // // pnt pntPlus(pnt a,pnt b){a.x+=b.x; a.y+=b.y; return a;} // pnt pntMinus(pnt a,pnt b){a.x-=b.x; a.y-=b.y; return a;} // pnt pntMultiple(pnt a,pnt b){pnt c; c.x=a.x*b.x-a.y*b.y; c.y=a.x*b.y+a.y*b.x; // return c;} pnt pntMultipleDouble(pnt a,double k){a.x*=k; a.y*=k; return a;} // pnt pntPolar(double r,double t){pnt a; a.x=r*cos(t); a.y=r*sin(t); return a;} // // int pntIsEqual(pnt a,pnt b){return pntSign(pntMinus(a,b))==0;} // // pnt pntRatation(pnt a,pnt o,double t){ // return pntPlus(pntMultiple(pntMinus(a,o),pntPolar(1.0,t)),o); // } // // pnt pntRatationEasy(pnt a,double t){ // return pntMultiple(a,pntPolar(1.0,t)); // } // // // line perpendicularBisectorOfSegment(pnt a, pnt b){ // line res; pnt mid, dir; // mid = pntMultipleDouble(pntPlus(a,b),0.5); // dir = pntRatationEasy( pntMinus(b,a), PI/2 ); // res.a = pntMinus(mid,dir); res.b = pntPlus(mid,dir); // return res; // } // // int doubleSolveSecondDegreeEquation(double a,double b,double c,double // *res1,double *res2){ // if(doubleSign(a)){ // double d=b*b-4*a*c; int m=doubleSign(d)+1; // if(m==1) *res1=-b/(2*a); // if(m==2){d=sqrt(d); *res1=(-b-d)/(2*a); *res2=(-b+d)/(2*a);} // return m; // } // if(doubleSign(b)){*res1 = -b/c; return 1;} // if(doubleSign(c)) return 0; return 3; // } // // int pntIntersectionLineCircle(line t,circle s,pnt *res1,pnt *res2){ // int m; double a,b,c,t1,t2,k1,k2; pnt ab=pntMinus(t.b, t.a); // a=b=0; c=-s.r*s.r; // t1=t.a.x-s.c.x; t2=t.b.x-t.a.x; a+=t2*t2; b+=2*t1*t2; c+=t1*t1; // t1=t.a.y-s.c.y; t2=t.b.y-t.a.y; a+=t2*t2; b+=2*t1*t2; c+=t1*t1; // m=doubleSolveSecondDegreeEquation(a,b,c,&k1,&k2); // if(m>=1) *res1 = pntPlus( t.a, pntMultipleDouble(ab,k1) ); // if(m>=2) *res2 = pntPlus( t.a, pntMultipleDouble(ab,k2) ); // return m; // } // // line pntGetLineFromCoefficient(double a,double b,double c){ // line res; // if( doubleSign(a)==0 ){ // res.a.x = 0; res.b.x = 1; // res.a.y = res.b.y = -c/b; // } else { // res.a.y=0; res.b.y=1; // res.a.x=-c/a; res.b.x=(-b-c)/a; // } // return res; // } // // int pntIntersectionCircleCircle(circle s1,circle s2,pnt *res1,pnt *res2){ // double a,b,c; line t; // double x1=s1.c.x, x2=s2.c.x, y1=s1.c.y, y2=s2.c.y, r1=s1.r, r2=s2.r; // if( pntIsEqual(s1.c,s2.c) ){ if( doubleSign(s1.r-s2.r)==0 ) return 3; // return 0; } a = 2*(x1-x2); b = 2*(y1-y2); c = (x2*x2-x1*x1) + (y2*y2-y1*y1) // - (r2*r2-r1*r1); t = pntGetLineFromCoefficient(a,b,c); return // pntIntersectionLineCircle(t,s1,res1,res2); // } // // int pntIntersectionLineLine(line s,line t,pnt *res){ // pnt p1=s.a, p2=s.b, p3=t.a, p4=t.b; // double r = (p4.y-p3.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p4.x-p3.x); // if( doubleSign(r)==0 ) return 0; // res->x = // (p3.x*p4.y-p3.y*p4.x)*(p2.x-p1.x)-(p1.x*p2.y-p1.y*p2.x)*(p4.x-p3.x); res->y // = (p3.y*p4.x-p3.x*p4.y)*(p2.y-p1.y)-(p1.y*p2.x-p1.x*p2.y)*(p4.y-p3.y); // res->x /= r; res->y /= -r; return 1; // } // // // int cs; // int ls; // circle c[4000]; // line l[4000]; // // double arr[60]; // double eval(double x, double y){ // rep(i,N) arr[i] = C[i] * sqrt( (X[i]-x)**2 + (Y[i]-y)**2 ); // sortA(N,arr); // return arr[K-1]; // } // // { // int k; // double x, y, x1, y1, x2, y2; // double res = double_inf; // pnt p1; // pnt p2; // rd(N,K,(X,Y,C)(N)); // // rep(i,N) p[i].x = X[i], p[i].y = Y[i]; // // rep(i,N) res <?= eval(X[i], Y[i]); // rep(i,N) rep(j,i+1,N){ // x = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); // y = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); // res <?= eval(x, y); // } // // rep(i,N) rep(j,i+1,N){ // if(C[i] == C[j]){ // l[ls++] = perpendicularBisectorOfSegment(p[i], p[j]); // } else { // x1 = (C[i] * X[i] + C[j] * X[j]) / (C[i] + C[j]); // y1 = (C[i] * Y[i] + C[j] * Y[j]) / (C[i] + C[j]); // x2 = (C[i] * X[i] - C[j] * X[j]) / (C[i] - C[j]); // y2 = (C[i] * Y[i] - C[j] * Y[j]) / (C[i] - C[j]); // c[cs].c.x = (x1 + x2) / 2; // c[cs].c.y = (y1 + y2) / 2; // c[cs++].r = sqrt( (x1-x2)**2 + (y1-y2)**2 ) / 2; // } // } // // rep(i,cs) rep(j,i+1,cs){ // k = pntIntersectionCircleCircle(c[i],c[j],&p1,&p2); // if(k>=1) res <?= eval(p1.x, p1.y); // if(k>=2) res <?= eval(p2.x, p2.y); // } // // rep(i,ls) rep(j,i+1,ls){ // k = pntIntersectionLineLine(l[i], l[j], &p1); // if(k==1) res <?= eval(p1.x, p1.y); // } // // rep(i,ls) rep(j,cs){ // k = pntIntersectionLineCircle(l[i],c[j],&p1,&p2); // if(k>=1) res <?= eval(p1.x, p1.y); // if(k>=2) res <?= eval(p2.x, p2.y); // } // // wt(res); // }
replace
1
2
1
2
0
p02764
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; using Vect = pair<long double, long double>; Vect operator+(Vect lhs, Vect rhs) { Vect ret = make_pair(0, 0); ret.first = lhs.first + rhs.first; ret.second = lhs.second + rhs.second; return ret; } Vect operator-(Vect &lhs, Vect &rhs) { Vect ret; ret.first = lhs.first - rhs.first; ret.second = lhs.second - rhs.second; return ret; } Vect operator*(long double lhs, const Vect &rhs) { return make_pair(lhs * rhs.first, lhs * rhs.second); } long double norm(const Vect &v) { return sqrt(v.first * v.first + v.second * v.second); } Vect rotate(Vect v, long double cost, long double sint) { return make_pair(v.first * cost - v.second * sint, v.first * sint + v.second * cost); } const long double EPS = 1e-12; int main() { int N, K; cin >> N >> K; vector<pair<Vect, long double>> xyc(N); for (int i = 0; i < N; i++) { long double x, y, c; cin >> x >> y >> c; xyc[i] = make_pair(make_pair(x, y), c); } long double ur = 1e7, lr = 0; for (int _ = 0; _ < 100; _++) { // cout << lr << ' ' << ur << endl; long double mid = (lr + ur) / 2; vector<Vect> center_cands; for (auto v : xyc) { center_cands.push_back(v.first); } for (auto m1 : xyc) { for (auto m2 : xyc) { long double r1 = mid / m1.second, r2 = mid / m2.second; long double l = norm(m1.first - m2.first); if (l < EPS) { continue; } if ((l <= r1 + r2 + EPS) && (l >= abs(r1 - r2)) - EPS) { long double cost = (r1 * r1 + l * l - r2 * r2) / (2 * r1 * l); long double sint = sqrt(1 - cost * cost); // cout << cost << ' ' << sint << endl; Vect diff = m2.first - m1.first; // Vect diff_norm = (1 / l) * (m2.first - m1.first); Vect v1 = m1.first + (r1 / l) * rotate(diff, cost, sint); Vect v2 = m1.first + (r1 / l) * rotate(diff, cost, -sint); center_cands.push_back(v1); center_cands.push_back(v2); } } } /* for(auto c: center_cands){ cout << '(' << c.first << ',' << c.second << ')' << ' '; }cout << endl; */ int max_cnt = 0; for (auto center : center_cands) { int cnt = 0; for (auto p : xyc) { long double dist = norm(center - p.first) * p.second; if (dist <= mid + EPS) { cnt++; } } max_cnt = max(max_cnt, cnt); } // cout << max_cnt << endl; if (max_cnt >= K) { ur = mid; } else { lr = mid; } } cout << setprecision(20) << (lr + ur) / 2 << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; using Vect = pair<long double, long double>; Vect operator+(Vect lhs, Vect rhs) { Vect ret = make_pair(0, 0); ret.first = lhs.first + rhs.first; ret.second = lhs.second + rhs.second; return ret; } Vect operator-(Vect &lhs, Vect &rhs) { Vect ret; ret.first = lhs.first - rhs.first; ret.second = lhs.second - rhs.second; return ret; } Vect operator*(long double lhs, const Vect &rhs) { return make_pair(lhs * rhs.first, lhs * rhs.second); } long double norm(const Vect &v) { return sqrt(v.first * v.first + v.second * v.second); } Vect rotate(Vect v, long double cost, long double sint) { return make_pair(v.first * cost - v.second * sint, v.first * sint + v.second * cost); } const long double EPS = 1e-12; int main() { int N, K; cin >> N >> K; vector<pair<Vect, long double>> xyc(N); for (int i = 0; i < N; i++) { long double x, y, c; cin >> x >> y >> c; xyc[i] = make_pair(make_pair(x, y), c); } long double ur = 1e7, lr = 0; for (int _ = 0; _ < 100; _++) { // cout << lr << ' ' << ur << endl; long double mid = (lr + ur) / 2; vector<Vect> center_cands; for (auto v : xyc) { center_cands.push_back(v.first); } for (auto m1 : xyc) { for (auto m2 : xyc) { long double r1 = mid / m1.second, r2 = mid / m2.second; long double l = norm(m1.first - m2.first); if (l < EPS) { continue; } if ((l <= r1 + r2) && (l >= abs(r1 - r2))) { long double cost = (r1 * r1 + l * l - r2 * r2) / (2 * r1 * l); long double sint = sqrt(1 - cost * cost); // cout << cost << ' ' << sint << endl; Vect diff = m2.first - m1.first; // Vect diff_norm = (1 / l) * (m2.first - m1.first); Vect v1 = m1.first + (r1 / l) * rotate(diff, cost, sint); Vect v2 = m1.first + (r1 / l) * rotate(diff, cost, -sint); center_cands.push_back(v1); center_cands.push_back(v2); } } } /* for(auto c: center_cands){ cout << '(' << c.first << ',' << c.second << ')' << ' '; }cout << endl; */ int max_cnt = 0; for (auto center : center_cands) { int cnt = 0; for (auto p : xyc) { long double dist = norm(center - p.first) * p.second; if (dist <= mid + EPS) { cnt++; } } max_cnt = max(max_cnt, cnt); } // cout << max_cnt << endl; if (max_cnt >= K) { ur = mid; } else { lr = mid; } } cout << setprecision(20) << (lr + ur) / 2 << endl; }
replace
65
66
65
66
TLE
p02765
Python
Runtime Error
n, r = map(int, input()) if n >= 10: print(r) else: print(r + 100 * (10 - n))
n, r = map(int, input().split()) if n >= 10: print(r) else: print(r + 100 * (10 - n))
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02765/Python/s819191130.py", line 1, in <module> n, r = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p02765
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define vi vector<float> #define vl vector<long long> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define loop(i, n) for (int i = 0; i < n; i++) #define pb push_back #define mp make_pair #define ll long long #define pii pair<float, float> #define umap unordered_map<ll, float> using namespace std; #define xx first #define yy second int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int n, r; cin >> n >> r; if (n >= 10) { cout << r << endl; } else { cout << r + 100 * (10 - n) << endl; } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define vi vector<float> #define vl vector<long long> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define loop(i, n) for (int i = 0; i < n; i++) #define pb push_back #define mp make_pair #define ll long long #define pii pair<float, float> #define umap unordered_map<ll, float> using namespace std; #define xx first #define yy second int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif int n, r; cin >> n >> r; if (n >= 10) { cout << r << endl; } else { cout << r + 100 * (10 - n) << endl; } return 0; }
replace
33
37
33
37
0
p02765
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, s; s = 0; cin >> n >> a >> b; long long v[100000008][1000000008]; for (int i = 0; i < n; i++) { v[i][0] = 1; v[i][i] = 1; } for (int i = 2; i < n; i++) { for (int j = 1; j < i; j++) { v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]) % 1000000007; } } v[n - 1][a] = 0; v[n - 1][b] = 0; for (int i = 0; i < n; i++) { s = s + v[n - 1][i]; s = s % 1000000007; } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n > 9) cout << k << endl; else cout << k + 100 * (10 - n) << endl; }
replace
4
24
4
10
-11
p02765
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios::sync_with_stdio(NULL); \ cin.tie(NULL) #define mod 1000000007 #define endl "\n" #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define ll long long typedef vector<ll> vecll; typedef vector<int> veci; typedef vector<char> vecc; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; #define pb push_back #define mp make_pair #define time 1.0 * clock() / CLOCKS_PER_SEC int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; if (n >= 10) cout << k; else { cout << k + (100 * (10 - n)); } return 0; }
#include <bits/stdc++.h> using namespace std; #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios::sync_with_stdio(NULL); \ cin.tie(NULL) #define mod 1000000007 #define endl "\n" #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define ll long long typedef vector<ll> vecll; typedef vector<int> veci; typedef vector<char> vecc; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; #define pb push_back #define mp make_pair #define time 1.0 * clock() / CLOCKS_PER_SEC int main() { fast; #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif ll n, k; cin >> n >> k; if (n >= 10) cout << k; else { cout << k + (100 * (10 - n)); } return 0; }
replace
30
32
30
32
0
p02765
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; int main() { vector<vector<vector<long long>>> U( 10000, vector<vector<long long>>(100, vector<long long>(12, 1000))); for (size_t i = 0; true; i++) { } int N, M; cin >> N >> M; cout << M + (max(0, 10 - N) * 100); }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; int main() { vector<vector<vector<long long>>> U( 10000, vector<vector<long long>>(100, vector<long long>(12, 1000))); int N, M; cin >> N >> M; cout << M + (max(0, 10 - N) * 100); }
replace
7
9
7
8
TLE
p02765
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define M 100001 #define endl "\n" #define all(a) (a).begin(), (a).end() #define lp(i, a, b) for (i = a; i < b; i++) #define lpr(i, a, b) for (i = a; i >= b; i--) #define F first #define S second #define pb push_back #define mp make_pair typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; int i, j, n, r; cin >> n >> r; int ans = (n < 10) ? r + (100 * (10 - n)) : r; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define M 100001 #define endl "\n" #define all(a) (a).begin(), (a).end() #define lp(i, a, b) for (i = a; i < b; i++) #define lpr(i, a, b) for (i = a; i >= b; i--) #define F first #define S second #define pb push_back #define mp make_pair typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; int main() { /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ fast; int i, j, n, r; cin >> n >> r; int ans = (n < 10) ? r + (100 * (10 - n)) : r; cout << ans << endl; return 0; }
replace
24
28
24
28
0
p02765
C++
Runtime Error
// DEEPANSHU RAWAT // BTECH/10530/18 #include <bits/stdc++.h> #define ull unsigned long long #define lld long long int #define infi LLONG_MAX #define ninfi LLONG_MIN #define ff first #define ss second #define pb push_back #define mp make_pair #define e endl #define mod 998244353 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif lld n, k; cin >> n >> k; if (n > 10) { cout << k; } else { cout << k + 100 * (10 - n); } }
// DEEPANSHU RAWAT // BTECH/10530/18 #include <bits/stdc++.h> #define ull unsigned long long #define lld long long int #define infi LLONG_MAX #define ninfi LLONG_MIN #define ff first #define ss second #define pb push_back #define mp make_pair #define e endl #define mod 998244353 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ lld n, k; cin >> n >> k; if (n > 10) { cout << k; } else { cout << k + 100 * (10 - n); } }
replace
20
24
20
26
0
p02765
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) (x).begin(), (x).end() int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int n, r; cin >> n >> r; if (n >= 10) cout << r; else { cout << r + 100 * (10 - n); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) (x).begin(), (x).end() int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios::sync_with_stdio(0); cin.tie(0); int n, r; cin >> n >> r; if (n >= 10) cout << r; else { cout << r + 100 * (10 - n); } return 0; }
replace
12
16
12
16
0
p02765
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<int> vi; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define fn for (int i = 0; i < n; i++) #define all(x) x.begin(), x.end() #define endl "\n" void solve() { // write your code here : long long n, r; cin >> n >> r; if (n >= 10) cout << r; else cout << 100 * (10 - n) + r; } int main() { IOS #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t; // cin>>t; // while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<int> vi; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define fn for (int i = 0; i < n; i++) #define all(x) x.begin(), x.end() #define endl "\n" void solve() { // write your code here : long long n, r; cin >> n >> r; if (n >= 10) cout << r; else cout << 100 * (10 - n) + r; } int main() { // IOS // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif // int t; // cin>>t; // while(t--) solve(); }
replace
25
30
25
30
0
p02765
C++
Runtime Error
#include <stdio.h> int main(void) { int n, r, a; scanf("%d,&n"); scanf("%d,&r"); if (n >= 10) a = r; else a = r + 100 * (10 - n); printf("%d\n", a); return 0; }
#include <stdio.h> int main(void) { int n, r, a; scanf("%d", &n); scanf("%d", &r); if (n >= 10) a = r; else a = r + 100 * (10 - n); printf("%d\n", a); return 0; }
replace
4
6
4
6
-11
p02765
C++
Runtime Error
#include <bits/stdc++.h> #define FILE #define fr first #define se second using namespace std; const long long N = 2e5 + 7; const long long inf = 1e9 + 7; const long long mod = 1e9 + 7; int n; int k; int main() { #ifdef FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin >> n >> k; cout << k + 100 * (10 - min(10, n)) << "\n"; }
#include <bits/stdc++.h> #define FILE #define fr first #define se second using namespace std; const long long N = 2e5 + 7; const long long inf = 1e9 + 7; const long long mod = 1e9 + 7; int n; int k; int main() { #ifdef FILEs freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin >> n >> k; cout << k + 100 * (10 - min(10, n)) << "\n"; }
replace
15
16
15
16
0
p02766
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i) #define REPR(i, n) for (int i = (n)-1; i >= 0; --i) #define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i) #define REPx(x, a) for (auto x : a) #define ALL(a) a.begin(), a.end() #define SORT(a) sort(ALL(a)) #define SORTR(a) sort(ALL(a), greater<int>()) #define REVERSE(a) reverse(ALL(a)) #define bit_search(bit, n) REP(bit, 1 << (n)) #define bit_check(bit, i) (bit >> (i)) & 1 #define setpre(n) fixed << setprecision((n)) #define UNIQUE(a) \ do { \ SORT(a); \ (a).erase(unique(ALL(a)), (a).end()); \ } while (0) #define MAX(a) *max_element(ALL(a)) #define MIN(a) *min_element(ALL(a)) #define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin() #define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin() #define INPUT(a) REP(i, a.size()) cin >> a[i]; #define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second; #define OUTPUT_PERMUTATION(n) \ do { \ VI v(n); \ iota(ALL(v), 1); \ do { \ REPx(x, v) cout << x << " "; \ ENDL \ } while (next_permutation(ALL(v))); \ } while (0); #define MAKE_PERMUTATION(n) \ do { \ VVI a(fact(n), VI(n)); \ int idx = 0; \ VI v(n); \ iota(ALL(v), 1); \ do { \ REP(i, n) a[idx][i] = v[i]; \ idx++; \ PER = a; \ } while (next_permutation(ALL(v))); \ } while (0); // int fact(), VVI PERを宣言しておく #define ENDL cout << endl; using namespace std; using LL = long long; using LD = long double; using PII = pair<int, int>; using VPII = vector<PII>; using PLL = pair<LL, LL>; using VPLL = vector<PLL>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VC = vector<char>; using VS = vector<string>; using VB = vector<bool>; using VD = vector<double>; const LL INF = 1e18; const LL MOD = 1e9 + 7; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } void END() { cout << 1 << endl; exit(0); } int main() { cin.tie(0); ios::sync_with_stdio(false); LL n, k; cin >> n >> k; LL i = 0; while (true) { if (pow(k, i) <= n && n < pow(k, i + 1)) { cout << i + 1; return 0; } } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i) #define REPR(i, n) for (int i = (n)-1; i >= 0; --i) #define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i) #define REPx(x, a) for (auto x : a) #define ALL(a) a.begin(), a.end() #define SORT(a) sort(ALL(a)) #define SORTR(a) sort(ALL(a), greater<int>()) #define REVERSE(a) reverse(ALL(a)) #define bit_search(bit, n) REP(bit, 1 << (n)) #define bit_check(bit, i) (bit >> (i)) & 1 #define setpre(n) fixed << setprecision((n)) #define UNIQUE(a) \ do { \ SORT(a); \ (a).erase(unique(ALL(a)), (a).end()); \ } while (0) #define MAX(a) *max_element(ALL(a)) #define MIN(a) *min_element(ALL(a)) #define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin() #define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin() #define INPUT(a) REP(i, a.size()) cin >> a[i]; #define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second; #define OUTPUT_PERMUTATION(n) \ do { \ VI v(n); \ iota(ALL(v), 1); \ do { \ REPx(x, v) cout << x << " "; \ ENDL \ } while (next_permutation(ALL(v))); \ } while (0); #define MAKE_PERMUTATION(n) \ do { \ VVI a(fact(n), VI(n)); \ int idx = 0; \ VI v(n); \ iota(ALL(v), 1); \ do { \ REP(i, n) a[idx][i] = v[i]; \ idx++; \ PER = a; \ } while (next_permutation(ALL(v))); \ } while (0); // int fact(), VVI PERを宣言しておく #define ENDL cout << endl; using namespace std; using LL = long long; using LD = long double; using PII = pair<int, int>; using VPII = vector<PII>; using PLL = pair<LL, LL>; using VPLL = vector<PLL>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VC = vector<char>; using VS = vector<string>; using VB = vector<bool>; using VD = vector<double>; const LL INF = 1e18; const LL MOD = 1e9 + 7; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } void END() { cout << 1 << endl; exit(0); } int main() { cin.tie(0); ios::sync_with_stdio(false); LL n, k; cin >> n >> k; LL i = 0; while (true) { if (pow(k, i) <= n && n < pow(k, i + 1)) { cout << i + 1; return 0; } i++; } return 0; }
insert
102
102
102
103
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0; while (n / k >= 0) { ans++; n /= k; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0; while (n > 0) { ans++; n /= k; } cout << ans << endl; return 0; }
replace
11
12
11
12
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K, ans = 0; cin >> N >> K; for (int i = 0;; i++) { if (pow(K, i) < N && pow(K, i + 1) > N) { ans = i + 1; break; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K, ans = 0; cin >> N >> K; while (N) { N /= K; ans++; } cout << ans; return 0; }
replace
7
12
7
11
TLE
p02766
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; while (N > 0) { N / K; ans++; } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; while (N > 0) { N /= K; ans++; } cout << ans << endl; }
replace
7
8
7
8
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n, k; cin >> n >> k; int cnt = 0; while (n > 0) { cnt++; n / k; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n, k; cin >> n >> k; int cnt = 0; while (n > 0) { cnt++; n = n / k; } cout << cnt << endl; return 0; }
replace
10
11
10
11
TLE
p02766
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n; int k; cin >> n >> k; int result = 0; for (int i = 0; i < 1000000000; i++) { n = n / k; result++; } cout << result << endl; }
#include <iostream> using namespace std; int main() { int n; int k; cin >> n >> k; int result = 0; while (n > 0) { n = n / k; result++; } cout << result << endl; }
replace
9
10
9
10
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; int i = 1; while (true) { if (n < pow(k, i)) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; int i = 1; while (true) { if (n < pow(k, i)) { cout << i << endl; return 0; } else i++; } }
replace
12
13
12
14
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; int c = 0; while (n != 1) { n /= k; c++; } cout << ++c; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; int c = 0; while (n >= k) { n /= k; c++; } cout << ++c; return 0; }
replace
8
9
8
9
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a; cin >> n >> k; while (n > k) { if (n / k > k) { n /= k; a++; } } a++; cout << a << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a; cin >> n >> k; a = 0; while (n >= k) { n /= k; a++; } a++; cout << a << endl; }
replace
6
11
6
10
TLE
p02766
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; int tmp = N; int count = 0; do { tmp = tmp / K; count++; } while (tmp > 0); cout << count << endl; return 1; }
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; int tmp = N; int count = 0; do { tmp = tmp / K; count++; } while (tmp > 0); cout << count << endl; return 0; }
replace
16
17
16
17
1
p02766
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k; cin >> n >> k; cout << (ll)(log(n) / log(k)) + 1 << "\n"; }
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> int main() { /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k; cin >> n >> k; cout << (ll)(log(n) / log(k)) + 1 << "\n"; }
replace
43
48
43
48
0
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; while (N > 0) { N / K; ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; while (N > 0) { N /= K; ans++; } cout << ans << endl; }
replace
8
9
8
9
TLE
p02766
C++
Runtime Error
#include <iostream> int main(void) { long n; int k; int counter = 1; while (n >= k) { counter += 1; n = (n - n % k) / k; } std::cout << counter; }
#include <iostream> int main(void) { long n; int k; int counter = 1; std::cin >> n >> k; while (n >= k) { counter += 1; n = (n - n % k) / k; } std::cout << counter; }
insert
5
5
5
6
0
p02766
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; string st; int main() { int n, p, d; char c; do { d = n % p; n = n / p; if (d >= 0 && d <= 9) { c = d + '0'; } else { c = d + 55; } st = c + st; } while (n != 0); cout << st.size(); return 0; }
#include <bits/stdc++.h> using namespace std; string st; int main() { int n, p, d; cin >> n >> p; char c; do { d = n % p; n = n / p; if (d >= 0 && d <= 9) { c = d + '0'; } else { c = d + 55; } st = c + st; } while (n != 0); cout << st.size(); return 0; }
insert
5
5
5
6
0
p02766
Python
Runtime Error
MAX_N = 1_000_000_000 n, k = map(int, input().split()) for i in range(MAX_N): if n < pow(k, i): print(i) break
MAX_N = pow(10, 9) n, k = map(int, input().split()) for i in range(MAX_N): if n < pow(k, i): print(i) break
replace
0
1
0
1
0
p02766
Python
Time Limit Exceeded
n, k = map(int, input().split()) for i in range(2**n): # if k ** (i - 1) - 1 < n <= k ** i - 1: if n <= k**i - 1: print(i) exit()
n, k = map(int, input().split()) for i in range(2**31): if n <= k**i - 1: print(i) exit()
replace
2
4
2
3
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; while (N > 0) { N / K; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; while (N > 0) { N /= K; ans++; } cout << ans << endl; return 0; }
replace
10
11
10
11
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { double N, R, ans; cin >> N >> R; for (long long i = 1; i <= 100000000; i++) { if (N >= pow(R, i) && N < pow(R, i + 1)) { ans = i + 1; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double N, R, ans; cin >> N >> R; for (int i = 0; i <= 30; i++) { if (N >= pow(R, i) && N < pow(R, i + 1)) { ans = i + 1; break; } } cout << ans << endl; }
replace
5
6
5
6
TLE
p02766
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N, K, count = 0; cin >> N >> K; while (N >= K) { count++; } cout << count + 1 << endl; }
#include <iostream> using namespace std; int main() { int N, K, count = 0; cin >> N >> K; while (N >= K) { count++; N = N / K; } cout << count + 1 << endl; }
insert
7
7
7
8
TLE
p02766
C++
Runtime Error
#include "bits/stdc++.h" #define allr(x) x.rbegin(), x.rend() #define all(x) x.begin(), x.end() #define sp " " #define double long double #define pb push_back #define ff first #define int long long #define ss second #define vi vector<int> #define mem(ara, a) memset(ara, a, sizeof(ara)) #define bruh freopen("bruh.txt", "r", stdin) #define fo freopen("output.txt", "w", stdout) #define pii pair<int, int> long long inf = 2e18; long long minf = -inf; using namespace std; signed main() { #ifndef ONLINE_JUDGE freopen("bruh.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int ans = 0; while (n > 0) { n /= k; ans++; } cout << ans << endl; }
#include "bits/stdc++.h" #define allr(x) x.rbegin(), x.rend() #define all(x) x.begin(), x.end() #define sp " " #define double long double #define pb push_back #define ff first #define int long long #define ss second #define vi vector<int> #define mem(ara, a) memset(ara, a, sizeof(ara)) #define bruh freopen("bruh.txt", "r", stdin) #define fo freopen("output.txt", "w", stdout) #define pii pair<int, int> long long inf = 2e18; long long minf = -inf; using namespace std; signed main() { #ifndef ONLINE_JUDGE // freopen("bruh.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int ans = 0; while (n > 0) { n /= k; ans++; } cout << ans << endl; }
replace
23
25
23
25
0
p02766
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n, k, cnt = 0; cin >> n >> k; while (n % k >= 0) { cnt++; n /= k; } cout << cnt << endl; return 0; }
#include <iostream> using namespace std; int main() { int n, k, cnt = 0; cin >> n >> k; while (n > 0) { cnt++; n /= k; } cout << cnt << endl; return 0; }
replace
8
9
8
9
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int kai = N, count = 0; while (kai != 0) { kai = N / K; count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int count = 0; while (N != 0) { N = N / K; count++; } cout << count << endl; }
replace
7
10
7
10
TLE
p02766
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <chrono> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int get_digits(int n, int k) { int ret = 0; do { ret++; n /= k; } while (n > 0); return ret; } int main() { file(); int n, k; scanf("%d %d", &n, &k); printf("%d\n", get_digits(n, k)); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <chrono> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int get_digits(int n, int k) { int ret = 0; do { ret++; n /= k; } while (n > 0); return ret; } int main() { // file(); int n, k; scanf("%d %d", &n, &k); printf("%d\n", get_digits(n, k)); return 0; }
replace
38
39
38
39
0
p02766
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n; int res = 1; while (n > 0) { n /= k; res++; } cout << res << "\n"; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int res = 0; while (n > 0) { n /= k; res++; } cout << res << "\n"; }
replace
32
34
32
34
0
p02766
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> #include <cstdlib> using namespace std; int main() { int N; int K; cin >> N >> K; int L = 1; for (int i = 0; i < N; i++) { if (N / K != 0) { L++; K *= K; } else break; } cout << L << endl; }
#include <bits/stdc++.h> #include <cmath> #include <cstdlib> using namespace std; int main() { int N; int K; cin >> N >> K; int L = 1; while (N / K != 0) { L++; N /= K; } cout << L << endl; }
replace
9
15
9
12
0
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; // using P = pair<int,int>; int main() { int n, k; int counts = 0; cin >> n >> k; while (n != 1) { counts++; n /= k; } cout << counts + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; // using P = pair<int,int>; int main() { int n, k; int counts = 0; cin >> n >> k; while (n >= k) { counts++; n /= k; } cout << counts + 1 << endl; }
replace
10
11
10
11
TLE
p02766
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long n, k, c; cin >> n, k; c = 0; while (n) { c++; n = n / k; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n, k, c; cin >> n >> k; c = 0; while (n) { c++; n = n / k; } cout << c; return 0; }
replace
5
6
5
6
0
p02766
Python
Time Limit Exceeded
n, k = map(int, input().split()) counter = 1 while n != 1: n = int(n / k) counter += 1 print(counter)
n, k = map(int, input().split()) counter = 1 while n >= k: n = int(n / k) counter += 1 print(counter)
replace
2
3
2
3
TLE
p02766
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int N, K; cin >> N >> K; int ans = 1; int tmp = N; while (1) { if (tmp == 1) break; tmp /= K; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int N, K; cin >> N >> K; int ans = 1; int tmp = N; while (1) { if (tmp < K) break; tmp /= K; ans++; } cout << ans << endl; return 0; }
replace
12
13
12
13
TLE
p02767
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define dunk(a) cout << (a) << endl using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<int> X(N); rep(i, N) cin >> X[i]; vector<int> S(X[N - 1] - X[0] + 1); for (int P = X[0]; P <= X[N - 1]; ++P) { rep(i, N) S[P - X[0]] += (X[i] - P) * (X[i] - P); } sort(all(S)); dunk(S[0]); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define dunk(a) cout << (a) << endl using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<int> X(N); rep(i, N) cin >> X[i]; sort(all(X)); vector<int> S(X[N - 1] - X[0] + 1); for (int P = X[0]; P <= X[N - 1]; ++P) { rep(i, N) S[P - X[0]] += (X[i] - P) * (X[i] - P); } sort(all(S)); dunk(S[0]); }
insert
12
12
12
13
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); for (int i = 0; i < n; i++) cin >> vec.at(i); vector<int> cost(100); int camp; for (int i = 1; i < 101; i++) { for (int j = 0; j < n; j++) { camp = i; cost.at(i - 1) += (i - vec.at(j)) * (i - vec.at(j)); } } int answer = cost.at(0); for (int i = 0; i < 100; i++) { if (cost.at(i) < cost.at(i + 1)) answer = cost.at(i + 1); } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); for (int i = 0; i < n; i++) cin >> vec.at(i); vector<int> cost(100); int camp; for (int i = 1; i < 101; i++) { for (int j = 0; j < n; j++) { camp = i; cost.at(i - 1) += (i - vec.at(j)) * (i - vec.at(j)); } } int answer = cost.at(0); for (int i = 0; i < 99; i++) { if (cost.at(i) > cost.at(i + 1)) answer = cost.at(i + 1); } cout << answer << endl; }
replace
23
25
23
25
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 100) >= this->size() (which is 100)
p02767
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; const unsigned int M = 1e9 + 7; int32_t main() { fastio; int n; cin >> n; vector<int> a(n); int mn = INT_MAX, mx = INT_MIN; for (int i = 0; i < n; ++i) { cin >> a[i]; mn = min(mn, a[i]); mx = max(mx, a[i]); } int ans = INT_MAX; for (int i = mn; i <= mx; ++i) { int curr = 0; for (int j : a) curr += (j - i) * (j - i); ans = min(ans, curr); } cout << ans; return 0; }
#include <bits/stdc++.h> #define int long long #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; const unsigned int M = 1e9 + 7; int32_t main() { fastio; int n; cin >> n; vector<int> a(n); int mn = INT_MAX, mx = INT_MIN; for (int i = 0; i < n; ++i) { cin >> a[i]; mn = min(mn, a[i]); mx = max(mx, a[i]); } int ans = INT_MAX; for (int i = mn; i <= mx; ++i) { int curr = 0; for (int j = 0; j < n; ++j) curr += (a[j] - i) * (a[j] - i); ans = min(ans, curr); } cout << ans; return 0; }
replace
27
29
27
29
TLE
p02767
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int n; cin >> n; int max_x = 0; vector<int> X; for (int i = 0; i < n; i++) { int x; cin >> x; if (max_x < x) { max_x = x; } X.push_back(x); } vector<long> HP; for (int i = 1; i < max_x; i++) { long hp = 0; for (int j = 0; j < n; j++) { hp += (X[j] - i) * (X[j] - i); // cout << "hp " << hp << endl; } HP.push_back(hp); } cout << *std::min_element(HP.begin(), HP.end()) << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int n; cin >> n; int max_x = 0; vector<int> X; for (int i = 0; i < n; i++) { int x; cin >> x; if (max_x < x) { max_x = x; } X.push_back(x); } vector<long> HP; for (int i = 1; i <= max_x; i++) { long hp = 0; for (int j = 0; j < n; j++) { hp += (X[j] - i) * (X[j] - i); // cout << "hp " << hp << endl; } HP.push_back(hp); } cout << *std::min_element(HP.begin(), HP.end()) << endl; }
replace
26
27
26
27
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); int ans = 1e8; for (int i = x.at(0); i <= x.at(n - 1); i++) { int sum = 0; for (int j = 0; j < n; j++) { sum += pow(x.at(i) - i, 2.0); } ans = min(ans, sum); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); int ans = 1e8; for (int i = x.at(0); i <= x.at(n - 1); i++) { int sum = 0; for (int j = 0; j < n; j++) { sum += pow(x.at(j) - i, 2.0); } ans = min(ans, sum); } cout << ans << endl; }
replace
15
16
15
16
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define qmod 998244353 #define M 1000001 #define endl "\n" #define all(a) (a).begin(), (a).end() #define rep(i, a, b) for (int i = a; i < b; ++i) #define repr(i, a, b) for (int i = a; i >= b; --i) #define F first #define S second #define pb push_back #define mp make_pair typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; int n; cin >> n; int a[n], mi = 101, mx = 0; rep(i, 0, n) { cin >> a[i]; mi = min(mi, a[i]); mx = max(mx, a[i]); } int ans = INT_MAX; rep(i, mi, mx + 1) { int p = 0; rep(j, 0, n) p += pow((a[j] - i), 2); ans = min(p, ans); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define qmod 998244353 #define M 1000001 #define endl "\n" #define all(a) (a).begin(), (a).end() #define rep(i, a, b) for (int i = a; i < b; ++i) #define repr(i, a, b) for (int i = a; i >= b; --i) #define F first #define S second #define pb push_back #define mp make_pair typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; int main() { /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif */ fast; int n; cin >> n; int a[n], mi = 101, mx = 0; rep(i, 0, n) { cin >> a[i]; mi = min(mi, a[i]); mx = max(mx, a[i]); } int ans = INT_MAX; rep(i, mi, mx + 1) { int p = 0; rep(j, 0, n) p += pow((a[j] - i), 2); ans = min(p, ans); } cout << ans; return 0; }
replace
25
29
25
29
-11
p02767
C++
Runtime Error
#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.at(i); } int un; if (n % 2 == 0) un = (a.at((n - 1) / 2 + 1) - a.at((n - 1) / 2)) / 2 + a.at((n - 1) / 2); else un = a.at(n - 1 / 2); long int ans = 0; for (int i = 0; i < n; i++) { ans += pow((un - a.at(i)), 2); } cout << ans << endl; }
#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.at(i); } int ans = 1000000; for (int i = 1; i < 101; i++) { int b = 0; for (int h = 0; h < n; h++) { b += pow(i - a.at(h), 2); } ans = min(ans, b); } cout << ans << endl; }
replace
10
18
10
17
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) (x).begin(), (x).end() ll sqr(ll x) { return x * x; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int x[n]; double num, sum = 0; int num1, num2; for (int i = 0; i < n; i++) { cin >> x[i]; sum += x[i]; } sum /= n; num1 = (int)(floor(sum)); num2 = (int)(ceil(sum)); ll st1 = 0, st2 = 0; for (int i = 0; i < n; i++) { st1 += sqr(x[i] - num1); st2 += sqr(x[i] - num2); } cout << min(st1, st2); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) (x).begin(), (x).end() ll sqr(ll x) { return x * x; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int x[n]; double num, sum = 0; int num1, num2; for (int i = 0; i < n; i++) { cin >> x[i]; sum += x[i]; } sum /= n; num1 = (int)(floor(sum)); num2 = (int)(ceil(sum)); ll st1 = 0, st2 = 0; for (int i = 0; i < n; i++) { st1 += sqr(x[i] - num1); st2 += sqr(x[i] - num2); } cout << min(st1, st2); return 0; }
replace
14
18
14
18
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); vector<int> sum(x.at(n)); for (int i = 0; i < x.at(n); i++) { for (int j = 0; j < n; j++) { sum.at(i) += pow((i + 1 - x.at(j)), 2); } } sort(sum.begin(), sum.end()); cout << sum.at(0) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); int max = x.at(n - 1); vector<int> sum(max); for (int i = 0; i < max; i++) { for (int j = 0; j < n; j++) { sum.at(i) += pow((i + 1 - x.at(j)), 2); } } sort(sum.begin(), sum.end()); cout << sum.at(0) << endl; }
replace
11
13
11
14
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; vector<int> X(N); cin >> N; for (int i = 0; i < N; i++) cin >> X[i]; int ans = 1e+8; for (int i = 1; i <= 100; i++) { int sum = 0; for (int j = 0; j < N; j++) sum += (X[j] - i) * (X[j] - i); ans = min(ans, sum); } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int X[120]; cin >> N; for (int i = 0; i < N; i++) cin >> X[i]; int ans = 1e+8; for (int i = 1; i <= 100; i++) { int sum = 0; for (int j = 0; j < N; j++) sum += (X[j] - i) * (X[j] - i); ans = min(ans, sum); } printf("%d", ans); return 0; }
replace
5
6
5
6
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p02767
C++
Time Limit Exceeded
#include <algorithm> #include <climits> #include <iostream> using namespace std; int main() { int n; int array[100005]; cin >> n; for (int i = 0; i < n; i++) { cin >> array[i]; } sort(array, array + n); int p = array[0]; int minimum = INT_MAX; while (p <= array[n - 1]) { int sum = 0; for (int i = 0; i < n; i++) { sum += (array[i] - p) * (array[i] - p); } minimum = min(minimum, sum); } cout << minimum << endl; return (0); }
#include <algorithm> #include <climits> #include <iostream> using namespace std; int main() { int n; int array[100005]; cin >> n; for (int i = 0; i < n; i++) { cin >> array[i]; } sort(array, array + n); int p = array[0]; int minimum = INT_MAX; while (p <= array[n - 1]) { int sum = 0; for (int i = 0; i < n; i++) { sum += (array[i] - p) * (array[i] - p); } minimum = min(minimum, sum); p++; } cout << minimum << endl; return (0); }
insert
21
21
21
22
TLE
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define forn(i, n) for (int i = 0; i < (int)n; ++i) #define for1(i, n) for (int i = 1; i <= (int)n; ++i) #define forr(i, n) for (int i = (int)n - 1; i >= 0; --i) #define forre(i, a, b) for (int i = (int)b; i >= (int)a; --i) #define fore(i, a, b) for (int i = (int)a; i <= (int)b; ++i) #define input(i, arr) \ for (int &i : arr) \ cin >> i; #define output(i, arr) \ for (int &i : arr) \ cout << i << " "; #define for_each(arr) for (auto &it : arr) #define ff first #define ss second #define PI acos(-1.0) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Unique(a) sort(all(a)), a.erase(unique(all(a)), a.end()) #define pb(x) push_back(x) #define eb(x) emplace_back(x) #define ppb(x) pop_back(x) #define pf(x) push_front(x) #define ppf(x) pop_front(x) #define in(x, y) insert({x, y}) #define Sort(a) sort(a.begin(), a.end()) #define mem(arr, a) memset(arr, a, sizeof arr) #define ins(a) insert(a) #define max2(a, b) max(a, b) #define max3(a, b, c) max(a, max(b, c)) #define max4(a, b, c, d) max(a, max3(b, c, d)) #define min2(a, b) min(a, b) #define min3(a, b, c) min(a, min(b, c)) #define min4(a, b, c, d) min(a, min3(b, c, d)) typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<char> vc; typedef vector<double> vd; /*inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void Set(int & n, int b) { n |= two(b); } inline void Reset(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/ /*int fx1[]={+1,-1,+0,+0}; int fy1[]={+0,+0,+1,-1}; int fx2={+0,+0,+1,-1,-1,+1,-1,+1}; int fy2={-1,+1,+0,+0,+1,+1,-1,-1}; */ ll a, b, c, n, ans, cn1, cn2, cn3, t; string s, s1, s2; int main() { FIO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt","w",stdout); #endif cin >> a; vector<int> v(a); int sum = 0; int mn = 103, mx = -1; for (int i = 0; i < a; i++) { cin >> v[i]; sum += v[i]; mn = min(mn, v[i]); mx = max(mx, v[i]); } // sort(v.begin(),v.end()); // cout<<sum<<endl; // cout<<b<<endl; b = sum / a; for (int i = 0; i < a; i++) { ans += abs(b - v[i]) * abs(b - v[i]); } b = sum / a + 1; ll ans1 = 0; for (int i = 0; i < a; i++) { ans1 += abs(b - v[i]) * abs(b - v[i]); } // cout<<ans<<endl; b = (mn + mx) / 2; ll ans2 = 0; for (int i = 0; i < a; i++) { ans2 += abs(b - v[i]) * abs(b - v[i]); } cout << min(ans, min(ans1, ans2)) << endl; #ifdef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define forn(i, n) for (int i = 0; i < (int)n; ++i) #define for1(i, n) for (int i = 1; i <= (int)n; ++i) #define forr(i, n) for (int i = (int)n - 1; i >= 0; --i) #define forre(i, a, b) for (int i = (int)b; i >= (int)a; --i) #define fore(i, a, b) for (int i = (int)a; i <= (int)b; ++i) #define input(i, arr) \ for (int &i : arr) \ cin >> i; #define output(i, arr) \ for (int &i : arr) \ cout << i << " "; #define for_each(arr) for (auto &it : arr) #define ff first #define ss second #define PI acos(-1.0) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Unique(a) sort(all(a)), a.erase(unique(all(a)), a.end()) #define pb(x) push_back(x) #define eb(x) emplace_back(x) #define ppb(x) pop_back(x) #define pf(x) push_front(x) #define ppf(x) pop_front(x) #define in(x, y) insert({x, y}) #define Sort(a) sort(a.begin(), a.end()) #define mem(arr, a) memset(arr, a, sizeof arr) #define ins(a) insert(a) #define max2(a, b) max(a, b) #define max3(a, b, c) max(a, max(b, c)) #define max4(a, b, c, d) max(a, max3(b, c, d)) #define min2(a, b) min(a, b) #define min3(a, b, c) min(a, min(b, c)) #define min4(a, b, c, d) min(a, min3(b, c, d)) typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<char> vc; typedef vector<double> vd; /*inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void Set(int & n, int b) { n |= two(b); } inline void Reset(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/ /*int fx1[]={+1,-1,+0,+0}; int fy1[]={+0,+0,+1,-1}; int fx2={+0,+0,+1,-1,-1,+1,-1,+1}; int fy2={-1,+1,+0,+0,+1,+1,-1,-1}; */ ll a, b, c, n, ans, cn1, cn2, cn3, t; string s, s1, s2; int main() { FIO; // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif cin >> a; vector<int> v(a); int sum = 0; int mn = 103, mx = -1; for (int i = 0; i < a; i++) { cin >> v[i]; sum += v[i]; mn = min(mn, v[i]); mx = max(mx, v[i]); } // sort(v.begin(),v.end()); // cout<<sum<<endl; // cout<<b<<endl; b = sum / a; for (int i = 0; i < a; i++) { ans += abs(b - v[i]) * abs(b - v[i]); } b = sum / a + 1; ll ans1 = 0; for (int i = 0; i < a; i++) { ans1 += abs(b - v[i]) * abs(b - v[i]); } // cout<<ans<<endl; b = (mn + mx) / 2; ll ans2 = 0; for (int i = 0; i < a; i++) { ans2 += abs(b - v[i]) * abs(b - v[i]); } cout << min(ans, min(ans1, ans2)) << endl; #ifdef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n"; #endif return 0; }
replace
64
68
64
68
-8
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl "\n" // #define int long long const int N = 1005; const int MOD = 1e9 + 7; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized */ int n; cin >> n; int arr[n]; int sum = 0; int count = 0, count1 = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } int x = (sum + n) / n; int x1 = sum / n; for (int i = 0; i < n; i++) { int z = abs(x - arr[i]); int z1 = abs(x1 - arr[i]); z = z * z; z1 = z1 * z1; count += z; count1 += z1; } cout << min(count, count1); }
#include <bits/stdc++.h> using namespace std; #define endl "\n" // #define int long long const int N = 1005; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized */ int n; cin >> n; int arr[n]; int sum = 0; int count = 0, count1 = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } int x = (sum + n) / n; int x1 = sum / n; for (int i = 0; i < n; i++) { int z = abs(x - arr[i]); int z1 = abs(x1 - arr[i]); z = z * z; z1 = z1 * z1; count += z; count1 += z1; } cout << min(count, count1); }
replace
9
13
9
10
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int n; cin >> n; vector<int> x(n); int sum = 0; int d_sum = 0; rep(i, n) { cin >> x.at(i); sum += x.at(i); d_sum += pow(x.at(i), 2); } int ans = 1000000; for (int i = 0; i < 100; i++) { int p = x.at(i); int pa = d_sum - 2 * sum * p + n * p * p; ans = min(pa, ans); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int n; cin >> n; vector<int> x(n); int sum = 0; int d_sum = 0; rep(i, n) { cin >> x.at(i); sum += x.at(i); d_sum += pow(x.at(i), 2); } int ans = 1000000; for (int i = 1; i <= 100; i++) { int p = i; int pa = d_sum - 2 * sum * p + n * p * p; ans = min(pa, ans); } cout << ans << endl; }
replace
16
18
16
18
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02767
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, nu = 1e9; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } for (int i = 1; i < 100; i++) { int hu = 0; for (int j = 0; j < n; i++) { hu += (x[j] - i) * (x[j] - i); } nu = min(nu, hu); } cout << nu << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, nu = 1e9; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } for (int i = 1; i < 100; i++) { int hu = 0; for (int j = 0; j < n; j++) { hu += (x[j] - i) * (x[j] - i); } nu = min(nu, hu); } cout << nu << endl; }
replace
12
13
12
13
TLE
p02767
C++
Runtime Error
#include <bits/stdc++.h> #define nl "\n" #define pb push_back #define sp " " typedef long long ll; #define len(x) x.length() #define vsort(x) sort(x.begin(), x.end(); using namespace std; ll inf = 2e18; int main() { ios::sync_with_stdio(false); cin.tie(0); freopen("bruh.txt", "r", stdin); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int mid = (arr[0] + arr[n - 1]) / 2; int mx = 1e9; int ans; for (int k = 0; k <= 100; k++) { ans = 0; mid = k; for (int i = 0; i < n; i++) { ans += (arr[i] - mid) * (arr[i] - mid); } mx = min(ans, mx); } cout << mx << nl; }
#include <bits/stdc++.h> #define nl "\n" #define pb push_back #define sp " " typedef long long ll; #define len(x) x.length() #define vsort(x) sort(x.begin(), x.end(); using namespace std; ll inf = 2e18; int main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("bruh.txt","r",stdin); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int mid = (arr[0] + arr[n - 1]) / 2; int mx = 1e9; int ans; for (int k = 0; k <= 100; k++) { ans = 0; mid = k; for (int i = 0; i < n; i++) { ans += (arr[i] - mid) * (arr[i] - mid); } mx = min(ans, mx); } cout << mx << nl; }
replace
16
17
16
17
-11
p02767
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int n, sum; sum = 0; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); vector<int> s; for (int p = x[0]; p < x[n - 1]; p++) { for (int i : x) { sum += (i - p) * (i - p); } s.push_back(sum); sum = 0; } sort(s.begin(), s.end()); cout << s[0] << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int n, sum; sum = 0; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); vector<int> s; for (int p = x[0]; p <= x[n - 1]; p++) { for (int i : x) { sum += (i - p) * (i - p); } s.push_back(sum); sum = 0; } sort(s.begin(), s.end()); cout << s[0] << endl; }
replace
18
19
18
19
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n = 0; cin >> n; vector<ll> v(n, 0); ll mn = 1e9 + 5; ll mx = -1e9 + 5; for (int i = 0; i < n; i++) { cin >> v[i]; mn = min(mn, v[i]); mx = max(mx, v[i]); } ll ans = 1e9 + 5; for (int i = mn; i <= mx; i++) { ll temp = 0; for (int j = 0; j < n; j++) { temp += pow(abs(v[j] - i), 2); } ans = min(ans, temp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n = 0; cin >> n; vector<ll> v(n, 0); ll mn = 1e9 + 5; ll mx = -1e9 + 5; for (int i = 0; i < n; i++) { cin >> v[i]; mn = min(mn, v[i]); mx = max(mx, v[i]); } ll ans = 1e9 + 5; for (int i = mn; i <= mx; i++) { ll temp = 0; for (int j = 0; j < n; j++) { temp += pow(abs(v[j] - i), 2); } ans = min(ans, temp); } cout << ans << endl; return 0; }
delete
6
11
6
6
0
p02767
Python
Runtime Error
N = int(input()) X_list = list(map(int, input().split())) hp_list = [] for p in range(int(min(X_list)), int(max(X_list))): hp = 0 for x in X_list: hp += abs(x - p) ** 2 hp_list.append(hp) print(min(hp_list))
N = int(input()) X_list = list(map(int, input().split())) hp_list = [] for p in range(int(min(X_list)), int(max(X_list))): hp = 0 for x in X_list: hp += abs(x - p) ** 2 hp_list.append(hp) print(min(hp_list) if len(hp_list) > 0 else 0)
replace
10
11
10
11
0
p02767
Python
Runtime Error
n = int(input()) x = list(map(int, input().split())) sum_list = [] start = min(x) stop = max(x) for i in range(start, stop): sum = 0 for j in x: sum += (i - j) ** 2 sum_list.append(sum) print(min(sum_list))
n = int(input()) x = list(map(int, input().split())) sum_list = [] start = min(x) stop = max(x) for i in range(1, 100): sum = 0 for j in x: sum += (i - j) ** 2 sum_list.append(sum) print(min(sum_list))
replace
6
7
6
7
0
p02767
Python
Runtime Error
n = int(input()) x = list(map(int, input().split())) sum_list = [] start = min(x) stop = max(x) for i in range(start, stop): sum = 0 for j in x: sum += (i - j) ** 2 sum_list.append(sum) print(min(sum_list))
n = int(input()) x = list(map(int, input().split())) sum_list = [] for i in range(1, 100): sum = 0 for j in x: sum += (i - j) ** 2 sum_list.append(sum) print(min(sum_list))
replace
4
7
4
5
0
p02767
Python
Runtime Error
N = int(input()) X = list(map(int, input().split())) minX = min(X) maxX = max(X) li = [] for i in range(minX, maxX): temp = 0 for j in range(N): temp += (X[j] - i) ** 2 li.append(temp) print(min(li))
N = int(input()) X = list(map(int, input().split())) minX = min(X) maxX = max(X) li = [] for i in range(100): temp = 0 for j in range(N): temp += (X[j] - i) ** 2 li.append(temp) print(min(li))
replace
6
7
6
7
0
p02767
Python
Runtime Error
import sys N = int(input()) X = [int(_) for _ in input().split()] ans_list = [] if N == 1: print("0") sys.exit() for i in range(min(X), max(X)): ans = 0 for j in X: ans += (j - i) ** 2 ans_list.append(ans) print(min(ans_list))
import sys N = int(input()) X = [int(_) for _ in input().split()] ans_list = [] if N == 1: print("0") sys.exit() for i in range(min(X), max(X) + 1): ans = 0 for j in X: ans += (j - i) ** 2 ans_list.append(ans) print(min(ans_list))
replace
8
9
8
9
0
p02767
Python
Runtime Error
N = int(input()) points = list(map(int, input().split(" "))) powers = [] for i in range(min(points), max(points)): power = 0 for point in points: power += (i - point) ** 2 powers.append(power) print(min(powers))
N = int(input()) points = list(map(int, input().split(" "))) powers = [] for i in range(min(points), max(points) + 1): power = 0 for point in points: power += (i - point) ** 2 powers.append(power) print(min(powers))
replace
4
5
4
5
0