text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
long long OO = 100000;
bool pred(const std::pair<std::string, int>& lhs,
const std::pair<std::string, int>& rhs) {
return lhs.second < rhs.second;
}
int main() {
int n;
cin >> n;
map<string, int> mp;
string s;
cin >> s;
vector<int> v;
for (int i = 0; i < s.length() - 1; i++) {
string x = "";
x += (s[i]);
x += s[i + 1];
mp[x]++;
}
cout << max_element(mp.begin(), mp.end(), pred)->first;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<string> v;
for (int i = 0; i < n - 1; i++) {
string ss;
ss += s[i];
ss += s[i + 1];
v.push_back(ss);
}
int sz = v.size();
map<string, int> mp;
for (int i = 0; i < sz; i++) {
mp[v[i]]++;
}
map<string, int>::iterator it = mp.begin();
string ans;
int mx = 0;
for (; it != mp.end(); it++) {
int cnt = it->second;
if (cnt > mx) {
ans = it->first;
mx = it->second;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct diagram {
diagram(string str) {
name = str;
amount = 1;
}
string name;
int amount;
};
int main() {
int max = 0;
int n;
cin >> n;
string input;
cin >> input;
vector<diagram> arr;
for (int i = 0; i < input.length() - 1; i++) {
bool found = 0;
string temp = "";
temp.push_back(input[i]);
temp.push_back(input[i + 1]);
for (int i = 0; i < arr.size(); i++) {
if (temp == arr[i].name) {
arr[i].amount += 1;
found = true;
break;
}
}
if (!found) {
arr.push_back(diagram(temp));
}
}
for (int i = 0; i < arr.size(); i++) {
if (arr[i].amount > max) {
max = arr[i].amount;
}
}
for (int i = 0; i < arr.size(); i++) {
if (arr[i].amount == max) {
cout << arr[i].name;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, mx = 0;
char s[111];
int ans;
int main() {
scanf("%d%s", &n, s + 1);
for (int i = 1; i < n; i++) {
int cnt = 0;
for (int j = 1; j < n; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) cnt++;
}
if (cnt > mx) {
mx = cnt;
ans = i;
}
}
printf("%c%c\n", s[ans], s[ans + 1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
unordered_map<string, int> mp;
unordered_map<string, int>::iterator it;
for (int i = 0; i < n - 1; i++) {
string a = s.substr(i, 2);
it = mp.find(a);
if (it == mp.end())
mp.insert({a, 1});
else
it->second = it->second + 1;
}
it = mp.begin();
string ans = it->first;
int q = it->second;
it++;
for (; it != mp.end(); it++) {
if (it->second > q) {
q = it->second;
ans = it->first;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m = -1, i, j, k, x;
cin >> n;
string s;
char s5, s6;
cin >> s;
for (i = 0; i < n - 1; i++) {
char s1 = s[i];
char s2 = s[i + 1];
x = 1;
for (j = i + 1; j < n; j++) {
if (s1 == s[j] && s2 == s[j + 1] && j + 1 < n) {
x++;
}
}
if (x > m) {
m = x;
s5 = s1;
s6 = s2;
}
}
cout << s5 << s6 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, b[100] = {0}, c, ma, j, n;
char s[105];
cin >> n;
cin >> s;
for (i = 0; i < n - 1; i++) b[i] = 0;
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n - 1; j++)
if (s[j] == s[i] && s[j + 1] == s[i + 1]) b[i] = b[i] + 1;
}
ma = b[0];
c = 0;
for (i = 0; i < n - 1; i++)
if (b[i] > ma) {
c = i;
ma = b[i];
}
cout << s[c] << s[c + 1];
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> grams;
for (int i = 0; i < n - 1; i++) {
string k;
k.push_back(s[i]);
k.push_back(s[i + 1]);
if (grams.count(k) == 0)
grams[k] = 1;
else
grams[k] += 1;
}
int maxi = -1;
string gram = "";
for (auto e : grams) {
if (e.second > maxi) {
maxi = e.second;
gram = e.first;
}
}
cout << gram << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
map<string, int> m;
int n;
cin >> n;
cin >> s;
map<string, int>::iterator it;
for (int i = 0; i < n - 1; i++) {
string temp;
temp.push_back(s[i]);
temp.push_back(s[i + 1]);
it = m.find(temp);
if (it == m.end()) {
m.insert(make_pair(temp, 1));
} else
(it->second)++;
}
int ans = -1;
string q;
for (it = m.begin(); it != m.end(); it++) {
if (ans < it->second) {
q = it->first;
ans = it->second;
}
}
cout << q << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s) {
return f.second > s.second;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long conbinationMemo[100][100];
void cmemoInit() {
for (int i = 0; i < (int)(100); i++) {
for (int j = 0; j < (int)(100); j++) {
conbinationMemo[i][j] = -1;
}
}
}
long long nCr(long long n, long long r) {
if (conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
if (r == 0 || r == n) {
return 1;
} else if (r == 1) {
return n;
}
return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
long long nPr(long long n, long long r) {
r = n - r;
long long ret = 1;
for (long long i = n; i >= r + 1; i--) ret *= i;
return ret;
}
int main(void) {
long long n;
cin >> n;
string s;
cin >> s;
map<string, long long> mp;
for (int i = 0; i < (int)(n - 1); i++) {
mp[s.substr(i, 2)]++;
}
string ans = "";
long long ma = 0;
for (auto& i : mp) {
if (ma < i.second) {
ans = i.first;
ma = i.second;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
string s;
cin >> n >> s;
string x[n - 1];
for (int i = 0; i < n - 1; i++) x[i] = s.substr(i, 2);
sort(x, x + (n - 1));
int a = 1, b = 1, c = 0;
for (int i = 1; i < n - 1; i++) {
if (x[i] == x[i - 1]) {
a++;
if (a > b) {
b++;
c = i;
}
} else {
a = 1;
}
}
cout << x[c] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> cnt;
int main() {
long long n;
int l, mn = 0;
string s, tmp;
string sq(" ");
cin >> n >> s;
l = s.length();
for (int i = 1; i < l; i++) {
sq[0] = s[i - 1];
sq[1] = s[i];
if (sq.compare(0, 1, " ") && sq.compare(1, 1, " ")) {
cnt[sq]++;
}
}
map<string, int>::iterator it;
for (it = cnt.begin(); it != cnt.end(); it++) {
if (mn < it->second) {
mn = it->second;
tmp = it->first;
}
}
cout << tmp << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, e, m = 0;
cin >> n;
string s;
char c[2];
cin >> s;
for (int i = 0; i < n; i++) {
int b = 0;
c[0] = s[i];
c[1] = s[i + 1];
for (int j = i; j < n - 1; j++) {
if (s[j] == c[0] && s[j + 1] == c[1]) b++;
}
if (b > m) {
e = i;
m = b;
}
}
cout << s[e] << s[e + 1];
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
map<string, int> mp;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> s;
for (int i = 0; i < n - 1; ++i) {
++mp[s.substr(i, 2)];
}
int mx = 0;
string ans;
for (auto it : mp) {
if (it.second > mx) {
mx = it.second;
ans = it.first;
}
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
string ans = {s[0], s[1]};
int mx = 0;
map<string, int> mp;
for (int i = 0; i + 1 < n; ++i) mp[{s[i], s[i + 1]}]++;
for (auto p : mp)
if (p.second > mx) mx = p.second, ans = p.first;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, l, j, cnt = 0;
int maxi = 0;
string s, ans;
cin >> n;
cin >> s;
l = s.length();
for (i = 1; i < l; i++) {
string tmp;
tmp += s[i - 1];
tmp += s[i];
cnt = 0;
for (j = 1; j < l; j++) {
string tmp1;
tmp1 += s[j - 1];
tmp1 += s[j];
if (tmp == tmp1) cnt++;
}
if (maxi < cnt) {
maxi = cnt;
ans = tmp;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147380000;
const long long inf = 1e18;
const int maxn = 200;
map<string, int> ms;
int n;
string ans;
int Max;
char s[maxn];
int main() {
while (scanf("%d", &n) != EOF) {
scanf(" %s", s);
ms.clear();
Max = -1;
for (int i = 0; i < n - 1; i++) {
char S[5];
S[0] = s[i];
S[1] = s[i + 1];
S[2] = '\0';
string ss = (string)S;
if (ms.count(ss)) {
ms[ss]++;
} else {
ms[ss] = 1;
}
}
for (int i = 0; i < n - 1; i++) {
char S[5];
S[0] = s[i];
S[1] = s[i + 1];
S[2] = '\0';
string ss = (string)S;
if (ms[ss] > Max) {
Max = ms[ss];
ans = ss;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
map<string, int> mp;
int main() {
int n;
scanf("%d", &n);
string s;
cin >> s;
for (int i = 1; i < n; i++) {
string t;
t.push_back(s[i - 1]);
t.push_back(s[i]);
mp[t]++;
}
string ans;
int mx = -1;
for (auto to : mp) {
if (to.second > mx) {
mx = to.second;
ans = to.first;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second < b.second) return true;
return false;
}
void solve() {
int n;
cin >> n;
string s, gram;
cin >> s;
int ans = INT_MIN;
for (int i = 0; i < n - 1; i++) {
int cnt = 0;
string tgram = s.substr(i, 2);
for (int j = 0; j < n - 1; j++) {
string comp = s.substr(j, 2);
if (tgram == comp) {
cnt++;
}
}
if (cnt > ans) {
ans = cnt;
gram = tgram;
}
}
cout << gram << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a[n];
cin >> a;
int count[26][26] = {0};
int max = 0;
int ai, aj;
for (int i = 0; i < n - 1; i++) {
count[a[i] - 65][a[i + 1] - 65]++;
if (count[a[i] - 65][a[i + 1] - 65] > max) {
ai = a[i] - 65;
aj = a[i + 1] - 65;
max = count[a[i] - 65][a[i + 1] - 65];
}
}
cout << char(ai + 65) << char(aj + 65);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, max_index, max_count = 0;
cin >> n;
char* arr = new char[n];
cin >> arr;
for (int i = 1; i < n; i++) {
int count = 1;
for (int j = i + 1; j < n; j++) {
if (arr[i] == arr[j] && arr[i - 1] == arr[j - 1]) count++;
}
if (count > max_count) {
max_count = count;
max_index = i;
}
}
cout << arr[max_index - 1] << arr[max_index] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e5 + 20;
int main() {
long long n, i, j, m = -inf;
string s, ans;
cin >> n >> s;
for (i = 0; i < n - 1; ++i) {
string s2 = "";
s2 += s[i];
s2 += s[i + 1];
long long c = 0;
for (j = 0; j < n - 1; ++j) {
if (s[j] == s2[0] && s[j + 1] == s2[1]) c++;
}
if (c > m) {
m = c;
ans = s2;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int res = 0;
string ans;
char x, y;
for (int i = 0; i < n - 1; ++i) {
int cur = 0;
for (int j = 0; j < n - 1; ++j)
if (s[j] == s[i] && s[j + 1] == s[i + 1]) ++cur;
if (res < cur) {
res = cur;
x = s[i];
y = s[i + 1];
}
}
cout << x << y << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
string s;
cin >> s;
map<string, int> cnt;
string ans;
for (int i = 0; i < n - 1; i++) {
ans = s[i];
ans += s[i + 1];
cnt[ans]++;
}
int c = 0;
for (auto i : cnt) {
if (i.second > c) {
c = i.second;
ans = i.first;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, t;
int n;
cin >> n;
string s;
cin >> s;
std::map<string, int> m;
for (i = 0; i < (n - 1); i++) {
std::string p = s.substr(i, 2);
m[p]++;
}
int mx = 0;
string ans;
for (auto it = m.begin(); it != m.end(); it++) {
if ((int)it->second > mx) {
mx = (int)it->second;
ans = (string)it->first;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200100;
int main() {
int n, cnt = 0, maxCnt = -1;
string s, t, tt, ans;
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
t = s[i];
t += s[i + 1];
cnt = 0;
for (int j = i + 1; j < n - 1; j++) {
tt = s[j];
tt += s[j + 1];
if (t == tt) {
++cnt;
}
}
if (cnt > maxCnt) {
ans = t;
maxCnt = cnt;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count, max = 0;
cin >> n;
string s, S0, S1;
cin >> s;
for (int i = 0; i < n; i++) {
count = 0;
for (int j = 0; j < n; j++) {
if (s[i] == s[j] && s[i + 1] == s[j + 1]) count++;
}
if (count > max) {
max = count;
S0 = s[i];
S1 = s[i + 1];
}
}
cout << S0 << S1;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, R, vals[1 << 18];
double sum = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(18);
cin >> N >> R;
for (int i = 0; i < (1 << N); i++) {
cin >> vals[i];
sum += vals[i];
}
cout << sum / (1 << N) << '\n';
for (int i = 0; i < R; i++) {
int x, y;
cin >> x >> y;
sum += y - vals[x];
vals[x] = y;
cout << sum / (1 << N) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getrnd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
void solve() {
int n, r;
cin >> n >> r;
int pw = 1 << n;
ld res = 0;
vector<int> a(pw);
for (int i = 0; i < pw; ++i) cin >> a[i], res += (ld)a[i] / pw;
cout.precision(10);
cout << fixed << res << '\n';
for (int i = 0; i < r; ++i) {
int x, y;
cin >> x >> y;
res -= (ld)a[x] / pw;
res += (ld)y / pw;
a[x] = y;
cout << res << '\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
srand(time(0));
int t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 18;
int n, r;
double sum;
double a[(1 << MAXN) + 1];
int main(void) {
scanf("%d%d", &n, &r);
for (int i = 0; i < 1 << n; ++i) {
scanf("%lf", &a[i]);
sum += a[i];
}
printf("%.8lf\n", sum / (1 << n));
for (int i = 0; i < r; ++i) {
int z;
double g;
scanf("%d%lf", &z, &g);
sum += g - a[z];
a[z] = g;
printf("%.8lf\n", sum / (1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
int c[1 << 18];
int main() {
int n, r, i, z, g;
long long sum;
scanf("%d%d", &n, &r);
n = (1 << n);
sum = 0;
for (i = 0; i < n; ++i) {
scanf("%d", &c[i]);
sum += c[i];
}
printf("%.12f\n", sum * 1.0 / n);
while (r--) {
scanf("%d%d", &z, &g);
sum -= c[z];
sum += (c[z] = g);
printf("%.12f\n", sum * 1.0 / n);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, r, i, sum;
vector<long long> m;
int main() {
cin >> n >> r;
double k = 1 << n;
for (i = 0; i < k; i++) {
long long a;
cin >> a;
m.push_back(a);
sum += a;
}
cout.precision(10);
cout << fixed << (double)sum / k << '\n';
for (i = 0; i < r; i++) {
long long p;
cin >> p;
long long v;
cin >> v;
sum += v;
sum -= m[p];
m[p] = v;
cout << fixed << (double)sum / k << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long r;
scanf("%d %lld", &n, &r);
double sum = 0;
vector<int> c(1 << n);
for (int i = 0; i < (1 << n); i++) {
scanf("%d", &c[i]);
sum += c[i];
}
printf("%.6f\n", sum / (1 << n));
for (int i = 0; i < r; i++) {
int z, g;
scanf("%d %d", &z, &g);
sum = sum - c[z] + g;
c[z] = g;
printf("%.6f\n", sum / (1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(20);
int a[2000000];
int n;
cin >> n;
int q;
cin >> q;
int m = 1;
for (int i = 0; i < n; i++) {
m *= 2;
}
n = m;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
cout << (sum * 1.0) / (n * 1.0) << '\n';
for (int i = 0; i < q; i++) {
int j = 0;
cin >> j;
int a1;
cin >> a1;
sum += a1;
sum -= a[j];
a[j] = a1;
cout << (sum * 1.0) / (n * 1.0) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, r;
cin >> n >> r;
vector<double> num(1 << n);
double ans = 0;
for (int i = 0; i < (1 << n); ++i) {
cin >> num[i];
ans += num[i];
}
cout << setprecision(7) << ans / (1 << n) << "\n";
for (int i = 0; i < r; ++i) {
int temp, val;
cin >> temp >> val;
ans += val;
ans -= num[temp];
num[temp] = val;
cout << setprecision(7) << ans / (1 << n) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, r, a[262155], uu, vv;
long long sum;
int main() {
cin >> n >> r;
for (int i = 0; i < (1 << n); i++) {
scanf("%d", &a[i]);
sum += a[i];
}
printf("%.12f\n", (double)sum / (1 << n));
while (r--) {
scanf("%d %d", &uu, &vv);
sum -= a[uu];
a[uu] = vv;
sum += a[uu];
printf("%.12f\n", (double)sum / (1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n;
long long r, a[(1LL << 20)], x, y;
int main() {
scanf("%d %I64d", &n, &r);
long long sum = 0;
double qpw = 1;
for (int i = 1; i <= n; ++i) qpw *= 2;
for (int i = 1; i <= qpw; ++i) {
scanf("%I64d", &a[i]);
sum += a[i];
}
printf("%.6f\n", sum * 1.0 / qpw);
double ans = 0;
while (r--) {
scanf("%I64d %I64d", &x, &y);
sum += (y - a[x + 1]);
a[x + 1] = y;
ans = sum * 1.0 / qpw;
printf("%.6f\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 19;
const double pi = acos(-1);
int n, r;
double a[MAXN], tot;
int z, g;
int main() {
scanf("%d%d", &n, &r);
n = 1 << n;
for (int(i) = (0); (i) < (n); (i)++) {
scanf("%lf", a + i);
tot += a[i];
}
printf("%.8f\n", tot / n);
for (int(i) = (0); (i) < (r); (i)++) {
scanf("%d%d", &z, &g);
tot -= a[z];
a[z] = g;
tot += a[z];
printf("%.8f\n", tot / n);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, r;
long long f[(1 << 18) + 1];
long long sum(int up) {
long long ans = 0;
for (int i = 0; i <= up - 1; ++i) ans += f[i];
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> r;
int nos = 1 << n;
int up = nos;
for (int i = 0; i <= up - 1; ++i) cin >> f[i];
long long t = sum(nos);
cout << std::setprecision(9) << (double)t / (nos) << "\n";
for (int i = 1; i <= r; ++i) {
long long z, g;
cin >> z >> g;
long long change = g - f[z];
t += change;
cout.precision(9);
cout << std::setprecision(9) << (double)t / nos << "\n";
f[z] = g;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 1e6;
int n, r;
int v[N];
int main() {
scanf("%d %d", &n, &r);
for (int i = 0; i < (1 << n); i++) scanf("%d", &v[i]);
long long sum = 0;
for (int i = 0; i < (1 << n); i++) sum += v[i];
cout << fixed << setprecision(10);
double lim = (1 << n);
cout << sum / lim << endl;
for (int i = 0; i < r; i++) {
int a, b;
scanf("%d %d", &a, &b);
sum -= v[a];
v[a] = b;
sum += v[a];
cout << sum / lim << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxpq = priority_queue<T, vector<T>, less<T>>;
template <typename T1, typename T2, typename H1 = hash<T1>,
typename H2 = hash<T2>>
struct pair_hash {
size_t operator()(const pair<T1, T2>& p) const {
return 31 * H1{}(p.first) + H2{}(p.second);
}
};
char _inputBuffer[4096 + 1], *_inputPtr = _inputBuffer, _outputBuffer[4096], _c,
_sign, *_tempInputBuf = nullptr, _numBuf[128],
_tempOutputBuf[128], _fill = ' ';
const char* _delimiter = " ";
int _cur, _outputPtr = 0, _numPtr = 0, _precision = 6, _width = 0,
_tempOutputPtr = 0, _cnt;
unsigned long long _precisionBase = 1000000;
void read(int& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(unsigned int& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(long long& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(unsigned long long& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(double& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_c == '.')
for (double _div = 1.0;
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) += (_c - '0') / (_div *= 10))
;
if (_sign) (x) = -(x);
} while (0);
}
void read(long double& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_c == '.')
for (long double _div = 1.0;
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) += (_c - '0') / (_div *= 10))
;
if (_sign) (x) = -(x);
} while (0);
}
void read(char& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
} while (0);
}
void read(char* x) {
do {
_cur = 0;
do {
_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while (_c <= ' ');
do {
(x)[_cur++] = _c;
} while ((_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer,
1, 4096, stdin)] = '\0',
*_inputPtr++))) > ' ');
(x)[_cur] = '\0';
} while (0);
}
void read(string& x) {
do {
if (!_tempInputBuf) assert(0);
do {
_cur = 0;
do {
_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++));
} while (_c <= ' ');
do {
(_tempInputBuf)[_cur++] = _c;
} while ((_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer,
1, 4096, stdin)] = '\0',
*_inputPtr++))) > ' ');
(_tempInputBuf)[_cur] = '\0';
} while (0);
(x) = string(_tempInputBuf, _cur);
} while (0);
}
template <typename T, typename... Ts>
void read(T&& x, Ts&&... xs) {
read(x);
read(forward<Ts>(xs)...);
}
void write(bool x) {
do {
if (x)
(_tempOutputBuf[_tempOutputPtr++] = ('1'));
else
(_tempOutputBuf[_tempOutputPtr++] = ('0'));
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(int x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned int _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned int _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(unsigned int x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned int _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned int _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(long long x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned long long _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned long long _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(unsigned long long x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned long long _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned long long _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(double x) {
do {
if (std::isnan(x)) {
do {
int _slen = strlen("NaN");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("NaN"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if (std::isinf(x)) {
do {
int _slen = strlen("Inf");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("Inf"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
unsigned long long _I = (unsigned long long)(-(x));
unsigned long long _F = ((-(x)) - _I) * _precisionBase + (double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
unsigned long long _I = (unsigned long long)(x);
unsigned long long _F = ((x)-_I) * _precisionBase + (double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(long double x) {
do {
if (std::isnan(x)) {
do {
int _slen = strlen("NaN");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("NaN"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if (std::isinf(x)) {
do {
int _slen = strlen("Inf");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("Inf"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
unsigned long long _I = (unsigned long long)(-(x));
unsigned long long _F =
((-(x)) - _I) * _precisionBase + (long double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
unsigned long long _I = (unsigned long long)(x);
unsigned long long _F = ((x)-_I) * _precisionBase + (long double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(char x) {
do {
(_tempOutputBuf[_tempOutputPtr++] = (x));
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(char* x) {
do {
int _slen = strlen(x);
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = (x); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(const char* x) {
do {
int _slen = strlen(x);
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = (x); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(string& x) {
do {
for (int _i = 0; _i < (_width - (int)(x).length()); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < (int)(x).length();
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (x[_i++]),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - (int)(x).length()); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
template <typename T, typename... Ts>
void write(T&& x, Ts&&... xs) {
write(x);
for (const char* _p = _delimiter; *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
write(forward<Ts>(xs)...);
}
void writeln() {
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = ('\n'),
_outputPtr++);
}
template <typename... Ts>
void writeln(Ts&&... xs) {
write(forward<Ts>(xs)...);
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = ('\n'),
_outputPtr++);
}
void flush() {
do {
(fwrite(_outputBuffer, 1, _outputPtr, stdout), _outputPtr = 0);
fflush(stdout);
} while (0);
}
class IOManager {
public:
~IOManager() { flush(); }
};
unique_ptr<IOManager> _iomanager;
int N, Q;
long long A[(1 << 19)];
int main() {
_iomanager.reset(new IOManager());
do {
_precision = (9);
_precisionBase = 1;
for (int _i = 0; _i < (9); _i++, _precisionBase *= 10)
;
} while (0);
read(N, Q);
int NN = 1 << N;
long long sum = 0;
for (auto i = (0); i < (NN); i++) {
read(A[i]);
sum += A[i];
}
writeln(double(sum) / NN);
int z;
long long g;
for (auto i = (0); i < (Q); i++) {
read(z, g);
sum += g - A[z];
A[z] = g;
writeln(double(sum) / NN);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll x[1 << 18];
void safeout(long long sum, long long m) {
using ld = long double;
long long f = sum / m;
ld s = ld(sum % m) / (ld)m;
if (f >= 10) {
s += sum % 10;
cout << f / 10 << s << endl;
} else {
cout << (ld)sum / (ld)m << endl;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
ll n, r;
cin >> n >> r;
ll m = 1 << n;
ll sum = 0;
for (int i = 0; i < m; i++) cin >> x[i], sum += x[i];
cout << fixed << setprecision(7);
safeout(sum, m);
for (int i = 0; i < r; i++) {
ll a, b;
cin >> a >> b;
sum -= x[a];
x[a] = b;
sum += x[a];
safeout(sum, m);
}
}
|
#include <bits/stdc++.h>
int c[1 << 18];
int main() {
int n, r, i, z, g;
long long sum;
scanf("%d%d", &n, &r);
n = (1 << n);
sum = 0;
for (i = 0; i < n; ++i) {
scanf("%d", &c[i]);
sum += c[i];
}
printf("%.12f\n", sum * 1.0 / n);
while (r--) {
scanf("%d%d", &z, &g);
sum -= c[z];
sum += (c[z] = g);
printf("%.12f\n", sum * 1.0 / n);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2000009];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
int n, r;
cin >> n >> r;
int nn = pow(2, n);
unsigned long long sum = 0;
for (int i = 1; i <= pow(2, n); i++) {
cin >> a[i];
sum += a[i];
}
cout << setprecision(10);
cout << (double)sum / (double)nn << endl;
while (r--) {
int x, y;
cin >> x >> y;
sum -= a[x + 1];
a[x + 1] = y;
sum += a[x + 1];
cout << setprecision(10);
cout << (double)sum / (double)nn << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int max_n = 300011, log_n = 32, max_m = 111, mod = 1000000007,
inf = 1011111111;
int n, a[max_n], m;
long long s;
int main() {
cin >> n >> m;
for (int i = 0; i < (1 << n); ++i) {
scanf("%d", &a[i]);
s += a[i];
}
for (int i = 0; i <= m; ++i) {
printf("%.12f\n", 1.0 * s / (1 << n));
int x, y;
if (i == m) continue;
scanf("%d%d", &x, &y);
s -= a[x] - y;
a[x] = y;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
int n, Q, a[1 << 18];
long long tot;
int main() {
n = read(), Q = read();
for (int i = 0; i < (1 << n); ++i) {
a[i] = read();
tot += a[i];
}
printf("%.10lf\n", tot * 1.0 / (1 << n));
while (Q--) {
int x = read(), y = read();
tot -= a[x];
a[x] = y;
tot += a[x];
printf("%.10lf\n", tot * 1.0 / (1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, r, z, g;
scanf("%d%d", &n, &r);
double n2 = 1 << n, m = 0.0;
int C[1 << n];
int i = 0;
while (i < 1 << n) {
scanf("%d", &C[i]);
m += C[i++] / n2;
}
printf("%.7f\n", m);
while (r-- > 0) {
scanf("%d%d", &z, &g);
m -= (C[z] - g) / n2;
C[z] = g;
printf("%.7f\n", m);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long ans = 0, w = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch)) {
ans = (ans << 3) + (ans << 1) + ch - '0';
ch = getchar();
}
return ans * w;
}
long long n, sum = 0, r, a[(1 << 18) + 5];
int main() {
n = read(), r = read();
n = (1 << n);
for (int i = 1; i <= n; ++i) a[i] = read(), sum += a[i];
printf("%6lf", (double)sum / n);
while (r--) {
long long p = read() + 1, v = read();
sum = sum - a[p] + v;
a[p] = v;
printf("\n%6lf", (double)sum / n);
}
return 0;
}
|
#include <bits/stdc++.h>
long long dx[4] = {0, -1, 0, 1};
long long dy[4] = {1, 0, -1, 0};
using namespace std;
class pa3 {
public:
long long x, y, z;
pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x) return x < p.x;
if (y != p.y) return y < p.y;
return z < p.z;
}
bool operator>(const pa3 &p) const {
if (x != p.x) return x > p.x;
if (y != p.y) return y > p.y;
return z > p.z;
}
bool operator==(const pa3 &p) const {
return x == p.x && y == p.y && z == p.z;
}
bool operator!=(const pa3 &p) const {
return !(x == p.x && y == p.y && z == p.z);
}
};
class pa4 {
public:
double x;
long long y, z, w;
pa4(double x = 0, long long y = 0, long long z = 0, long long w = 0)
: x(x), y(y), z(z), w(w) {}
bool operator<(const pa4 &p) const {
if (x != p.x) return x < p.x;
if (y != p.y) return y < p.y;
if (z != p.z) return z < p.z;
return w < p.w;
}
bool operator>(const pa4 &p) const {
if (x != p.x) return x > p.x;
if (y != p.y) return y > p.y;
if (z != p.z) return z > p.z;
return w > p.w;
}
bool operator==(const pa4 &p) const {
return x == p.x && y == p.y && z == p.z && w == p.w;
}
};
class pa2 {
public:
long long x, y;
pa2(long long x = 0, long long y = 0) : x(x), y(y) {}
pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const pa2 &p) const {
return abs(x - p.x) == 0 && abs(y - p.y) == 0;
}
bool operator!=(const pa2 &p) const {
return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
}
};
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(x * a, y * a); }
Point operator/(double a) { return Point(x / a, y / a); }
double absv() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
}
};
struct Segment {
Point p1, p2;
};
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
bool parareru(Point a, Point b, Point c, Point d) {
return abs(cross(a - b, d - c)) < (1e-10);
}
double distance_ls_p(Point a, Point b, Point c) {
if (dot(b - a, c - a) < (1e-10)) return (c - a).absv();
if (dot(a - b, c - b) < (1e-10)) return (c - b).absv();
return abs(cross(b - a, c - a)) / (b - a).absv();
}
bool is_intersected_ls(Segment a, Segment b) {
if (a.p1 == b.p1 || a.p2 == b.p1 || a.p1 == b.p2 || a.p2 == b.p2)
return false;
if (parareru((a.p2), (a.p1), (a.p1), (b.p2)) &&
parareru((a.p2), (a.p1), (a.p1), (b.p1))) {
if (dot(a.p1 - b.p1, a.p1 - b.p2) < (1e-10)) return true;
if (dot(a.p2 - b.p1, a.p2 - b.p2) < (1e-10)) return true;
if (dot(a.p1 - b.p1, a.p2 - b.p1) < (1e-10)) return true;
if (dot(a.p1 - b.p2, a.p2 - b.p2) < (1e-10)) return true;
return false;
} else
return (cross(a.p2 - a.p1, b.p1 - a.p1) * cross(a.p2 - a.p1, b.p2 - a.p1) <
(1e-10)) &&
(cross(b.p2 - b.p1, a.p1 - b.p1) * cross(b.p2 - b.p1, a.p2 - b.p1) <
(1e-10));
}
double segment_dis(Segment a, Segment b) {
if (is_intersected_ls(a, b)) return 0;
double r = distance_ls_p(a.p1, a.p2, b.p1);
r = min(r, distance_ls_p(a.p1, a.p2, b.p2));
r = min(r, distance_ls_p(b.p1, b.p2, a.p2));
r = min(r, distance_ls_p(b.p1, b.p2, a.p1));
return r;
}
Point intersection_ls(Segment a, Segment b) {
Point ba = b.p2 - b.p1;
double d1 = abs(cross(ba, a.p1 - b.p1));
double d2 = abs(cross(ba, a.p2 - b.p1));
double t = d1 / (d1 + d2);
return a.p1 + (a.p2 - a.p1) * t;
}
string itos(long long i) {
ostringstream s;
s << i;
return s.str();
}
long long gcd(long long v, long long b) {
if (v > b) return gcd(b, v);
if (v == b) return b;
if (b % v == 0) return v;
return gcd(v, b % v);
}
double distans(double x1, double y1, double x2, double y2) {
double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
return sqrt(rr);
}
long long mod;
long long pr[2010];
long long inv[2010];
long long beki(long long wa, long long rr, long long warukazu) {
if (rr == 0) return 1 % warukazu;
if (rr == 1) return wa % warukazu;
if (rr % 2 == 1) return (beki(wa, rr - 1, warukazu) * wa) % warukazu;
long long zx = beki(wa, rr / 2, warukazu);
return (zx * zx) % warukazu;
}
void gya(long long ert) {
pr[0] = 1;
for (long long i = 1; i < ert; i++) {
pr[i] = (pr[i - 1] * i) % mod;
}
for (long long i = 0; i < ert; i++) inv[i] = beki(pr[i], mod - 2, mod);
}
long long a[1 << 18];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long n, r;
cin >> n >> r;
long long ans = 0;
for (long long i = 0; i < (1 << n); i++) {
cin >> a[i];
ans += a[i];
}
printf("%.10lf\n", (double)ans / ((1 << n) + 0.0));
for (long long i = 0; i < r; i++) {
long long x, e;
cin >> x >> e;
long long sa = e - a[x];
a[x] = e;
ans += sa;
printf("%.10lf\n", (double)ans / ((1 << n) + 0.0));
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, '/STACK:200000')
using namespace std;
const int M = 18;
const int N = 1 << 18;
int n, r;
double v[N];
int main() {
scanf("%d %d", &n, &r);
double ans = 0;
int t = (1 << n);
for (int i = 0; i < t; ++i) {
scanf("%lf", v + i);
ans += v[i];
}
printf("%.10lf\n", ans / (double)t);
for (int i = 0; i < r; ++i) {
int a, b;
scanf("%d %d", &a, &b);
ans -= v[a];
v[a] = b;
ans += v[a];
printf("%.10lf\n", ans / (double)t);
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, r;
std::cin >> n >> r;
size_t f_size = 1;
for (size_t i = 0; i < n; ++i) {
f_size *= 2;
}
std::vector<int> f(f_size);
double expect = 0;
for (size_t i = 0; i < f_size; ++i) {
std::cin >> f[i];
expect += f[i];
}
expect /= f_size;
std::cout << std::fixed << std::setprecision(10) << expect << "\n";
for (size_t game = 0; game < r; ++game) {
int z, g;
std::cin >> z >> g;
expect = expect + (-1. * f[z] + g) / f_size;
f[z] = g;
std::cout << std::fixed << std::setprecision(10) << expect << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const int N = 1e5 + 5;
int A[1 << 19];
double sum = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n, q;
cin >> n >> q;
n = 1 << n;
for (int i = 0; i < n; i++) {
cin >> A[i];
sum += A[i];
}
cout << fixed << setprecision(10) << sum / n << "\n";
while (q--) {
int id;
cin >> id;
sum -= A[id];
cin >> A[id];
sum += A[id];
cout << fixed << setprecision(10) << sum / n << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
long long a = (1 << n);
long double divv = a;
long long sum = 0, r, x, y;
long long A[a + 5];
cin >> r;
for (int i = 0; i < a; i++) {
cin >> A[i];
sum += A[i];
}
cout << setprecision(10) << fixed;
cout << sum / divv << "\n";
for (int i = 0; i < r; i++) {
cin >> x >> y;
sum -= A[x];
sum += y;
A[x] = y;
cout << sum / divv << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void Draganov47() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void print(long long a, long long b) {
long double sum = a;
long double k = b;
cout << setprecision(10) << fixed << sum / k << '\n';
}
int main() {
Draganov47();
int n, r;
cin >> n >> r;
vector<long long> a(1 << n);
long long sum = 0;
for (int i = 0; i < (1 << n); i++) {
cin >> a[i];
sum += a[i];
}
print(sum, (1 << n));
for (int i = 0; i < r; i++) {
int pos, val;
cin >> pos >> val;
sum -= a[pos];
a[pos] = val;
sum += val;
print(sum, (1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, r, sum(0);
vector<long long> x;
int main() {
cin >> n >> r;
double c = 1 << n;
for (long long i = 0; i < c; i++) {
long long a;
cin >> a;
x.push_back(a);
sum += a;
}
cout << setprecision(10) << fixed << (double)sum / c << "\n";
for (long long i = 0; i < r; i++) {
long long z, g;
cin >> z >> g;
sum += g;
sum -= x[z];
x[z] = g;
cout << fixed << (double)sum / c << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int myrand(int l, int r) {
int ret = rand();
ret <<= 15;
ret ^= rand();
if (ret < 0) ret = -ret;
ret %= (r - l + 1);
ret += l;
return ret;
}
template <typename F, typename S>
ostream& operator<<(ostream& os, const pair<F, S>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<T> >;
int n, r;
double a[1 << 18];
int32_t main() {
scanf("%d %d", &n, &r);
for (int i = 0; i < (1 << n); i++) {
scanf("%lf", &a[i]);
}
double s = 0;
for (int i = 0; i < (1 << n); i++) {
s += a[i];
}
printf("%.10lf\n", s / double(1 << n));
while (r--) {
int i;
double x;
scanf("%d %lf", &i, &x);
s -= a[i];
a[i] = x;
s += a[i];
printf("%.10lf\n", s / double(1 << n));
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
vector<int> edge[105];
const int maxn = 300500;
int main() {
int n, r;
double pown = 1;
cout.precision(6);
int a[maxn];
double ans = 0;
long long sum = 0;
cin >> n >> r;
for (int i = 0; i < n; i++) pown *= 2;
for (int i = 0; i < pown; i++) {
cin >> a[i];
sum += a[i];
}
ans = sum * 1.0 / pown;
cout << fixed << ans << endl;
for (int i = 0; i < r; i++) {
int x, num;
cin >> x >> num;
sum += (num - a[x]);
a[x] = num;
ans = sum * 1.0 / pown;
cout << fixed << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
long long n, r;
cin >> n >> r;
vector<int> v;
double rows = pow(2, n);
double sum = 0;
for (long long i = 0; i < rows; ++i) {
int k;
cin >> k;
sum += k;
v.push_back(k);
}
cout << setprecision(20) << sum / rows << '\n';
for (int i = 0; i < r; ++i) {
int pos, val;
cin >> pos >> val;
int dif = val - v[pos];
v[pos] = val;
sum += dif;
cout << setprecision(20) << sum / rows << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using v2d = vector<vector<T>>;
template <class T>
using v3d = vector<vector<vector<T>>>;
template <class T>
using v4d = vector<vector<vector<vector<T>>>>;
template <class T>
using prq = priority_queue<T>;
template <class T>
using rpq = priority_queue<T, vector<T>, greater<T>>;
int main() {
int n, r;
scanf("%d %d", &n, &r);
int m = 1 << n;
vec<int> x(m);
ll sum = 0;
for (auto& i : x) {
scanf("%d", &i);
sum += i;
}
printf("%.9f\n", sum / (double)m);
while (r--) {
int u, v;
scanf("%d %d", &u, &v);
sum += v - x[u];
x[u] = v;
printf("%.9f\n", sum / (double)m);
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int P = 18;
const int N = 1 << P;
int f[N];
int n, r, z, g;
long long sum;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> r;
int m = 1 << n;
for (int i = 0; i < m; i++) {
cin >> f[i];
sum += f[i];
}
cout << fixed << setprecision(7) << (double)sum / m << endl;
for (int i = 1; i <= r; i++) {
cin >> z >> g;
(sum -= f[z]) += g;
f[z] = g;
cout << fixed << setprecision(7) << (double)sum / m << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<long long> tab(1LL << n);
long long sum = 0;
for (int i = 0; i < (1 << n); i++) {
cin >> tab[i];
sum += tab[i];
}
long double val = (1LL << n);
cout.precision(8);
cout << fixed << sum / val << endl;
while (q-- > 0) {
long long x, v;
cin >> x >> v;
sum += v - tab[x];
tab[x] = v;
cout.precision(8);
cout << fixed << sum / val << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll x[1 << 18];
void out(ll sum, ll m) {
ll f = sum / m;
ld s = ld(sum % m) / (ld)m;
if (f >= 10) {
s += sum % 10;
cout << f / 10 << (ld)s / (ld)m << endl;
} else {
cout << (ld)sum / (ld)m << endl;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
ll n, r;
cin >> n >> r;
ll m = 1 << n;
ll sum = 0;
for (int i = 0; i < m; i++) cin >> x[i], sum += x[i];
cout << fixed << setprecision(7);
out(sum, m);
for (int i = 0; i < r; i++) {
ll a, b;
cin >> a >> b;
sum -= x[a];
x[a] = b;
sum += x[a];
out(sum, m);
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 18);
long long c[MAXN + 5], sum;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, K;
cin >> N >> K;
for (int i = 0; i < (1 << N); i++) {
cin >> c[i];
sum += c[i];
}
cout << fixed << setprecision(6) << (double)sum / (1 << N) << '\n';
for (int i = 0; i < K; i++) {
long long id, x;
cin >> id >> x;
sum -= c[id];
c[id] = x;
sum += x;
cout << fixed << setprecision(6) << (double)sum / (1 << N) << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;
struct init {
init() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
}
~init() {
cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
}
} init;
const long long N = (1 << 20), MOD = 1000 * 1000 * 1000 + 7;
const ldb EPS = 5e-12, HALF = 0.5;
long long a[N];
long long sum;
signed main() {
long long n, r;
cin >> n >> r;
for (auto i = (long long)0; i < (long long)(1 << n); ++i) {
cin >> a[i];
sum += a[i];
}
cout << sum / 1. / (1 << n) << '\n';
while (r--) {
long long x, g;
cin >> x >> g;
sum -= a[x];
sum += g;
a[x] = g;
cout << sum / 1. / (1 << n) << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
void solve() {
int n, r;
cin >> n >> r;
int n2 = 1 << n;
vector<int> f(n2);
for (int i = 0; i < n2; ++i) cin >> f[i];
long long sum = 0;
for (int i = 0; i < n2; ++i) sum += f[i];
cout << setprecision(9);
cout << (1.0 * sum / n2) << endl;
while (r-- > 0) {
int z, g;
cin >> z >> g;
sum += (g - f[z]);
f[z] = g;
cout << ((long double)sum / n2) << endl;
}
}
int main(int argc, char* argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 3e5 + 5;
const int M = 20;
long long power(long long x, unsigned long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
long long n, r;
cin >> n >> r;
long long sum = 0, m = 1LL << n;
long long arr[m], i;
for (i = 0; i < m; i++) {
cin >> arr[i];
sum += arr[i];
}
double ans = (sum * 1.0) / m;
printf("%0.10lf\n", ans);
for (i = 1; i <= r; i++) {
long long idx, val;
cin >> idx >> val;
sum -= arr[idx];
sum += val;
arr[idx] = val;
ans = (1.0 * sum) / m;
printf("%0.10lf\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
int read() {
int s = 0;
char c = getchar(), lc = '+';
while (c < '0' || '9' < c) lc = c, c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
return lc == '-' ? -s : s;
}
void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x < 10)
putchar(x + '0');
else {
write(x / 10);
putchar(x % 10 + '0');
}
}
void print(int x, char c = '\n') {
write(x);
putchar(c);
}
int a[N];
double sum = 0;
signed main() {
int n = read(), m = read();
for (int i = 0; i < (1 << n); i++) sum += a[i] = read();
printf("%.8lf\n", sum / (1 << n));
for (int i = 1; i <= m; i++) {
int x = read(), y = read();
sum -= a[x];
sum += a[x] = y;
printf("%.8lf\n", sum / (1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, r;
cin >> n >> r;
long double res = 0;
vector<int> v(1 << n);
for (int i = 0; i < (int)1 << n; i++) {
cin >> v[i];
res += v[i];
}
long double pw = 1;
for (int i = 0; i < (int)n; i++) pw *= 1.0 / 2;
cout << setprecision(8) << fixed << res * pw << "\n";
while (r--) {
int z, g;
cin >> z >> g;
res -= v[z];
res += g;
v[z] = g;
cout << res * pw << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2333333];
int main() {
int n, m;
scanf("%d%d", &n, &m);
n = (1 << n);
double sum = 0;
for (int i = 0; i < n; i++) scanf("%d", &a[i]), sum += a[i];
printf("%.6f\n", sum / n);
for (int i = 0; i < m; i++) {
int p, x;
scanf("%d%d", &p, &x);
sum -= a[p];
sum += x;
a[p] = x;
printf("%.6f\n", sum / n);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<double> vc;
int main() {
long long n, r;
double q;
double sum, ans, x1, x2;
while (scanf("%lld%lld", &n, &r) != EOF) {
sum = 0;
for (long long i = 0; i < 1 << n; i++) {
scanf("%lf", &q);
sum += q;
vc.push_back(q);
}
printf("%.7lf\n", sum / (1 << n));
for (int i = 0; i < r; i++) {
scanf("%lf%lf", &x1, &x2);
sum = sum - vc[x1] + x2;
vc[x1] = x2;
ans = sum / (1 << n);
printf("%.7lf\n", ans);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool s) { return to_string((int)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
const long double eps = 1e-12;
const int N = 3e5 + 9;
const int M = 1000000;
pair<int, pair<int, int>> a[N];
vector<int> g[N];
int from[N], ans[N], n,
s[][3] = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {-1, 1, 1},
{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {1, -1, -1}};
void dfs(int u, int sgn = 1) {
if (u < n) ans[u] = sgn;
for (int v : g[u]) {
dfs(v, sgn * from[v]);
}
}
int c[(1 << 19) + 9];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int u, f, n, r;
cin >> n >> r;
long long sum = 0;
for (int i = 0; i < (1 << n); i++) {
cin >> c[i];
sum += c[i];
}
cout << fixed << setprecision(20);
cout << 1.l * sum / (1 << n) << endl;
for (int i = 0; i < r; i++) {
cin >> u >> f;
sum = sum - c[u] + f;
c[u] = f;
cout << 1.l * sum / (1 << n) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r;
scanf("%d%d", &n, &r);
vector<double> c(1 << n);
double s = 0.0;
for (int i = 0; i < (1 << n); i++) {
scanf("%lf", &c[i]);
s += c[i];
}
double p = pow(2.0, n);
printf("%.7lf\n", s / p);
while (r--) {
int x;
double g;
scanf("%d%lf", &x, &g);
s += g - c[x];
c[x] = g;
printf("%.7lf\n", s / p);
}
return 0;
}
|
#include <bits/stdc++.h>
const int MAXN = 1 << 18;
int read() {
int x = 0;
char c = getchar();
bool f = 0;
while (c < '0' || c > '9') (c == '-') ? f = 1, c = getchar() : c = getchar();
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (48 ^ c), c = getchar();
return (f) ? -x : x;
}
int c[MAXN];
int main() {
int n = read(), r = read();
int pow = 1 << n;
long long sum = 0;
for (int i = 0; i < pow; ++i) {
c[i] = read();
sum += c[i];
}
printf("%.6lf\n", sum * 1.0 / pow);
for (int t = 0; t < r; ++t) {
int z = read(), g = read();
sum = sum - c[z] + g;
c[z] = g;
printf("%.6lf\n", sum * 1.0 / pow);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(6);
int n, r, a;
long long tot = 0, b;
cin >> n >> r;
vector<int> arr(1 << n);
for (int i = 0; i < arr.size(); ++i) {
cin >> arr[i];
tot += arr[i];
}
cout << tot / ((1 << n) + 0.0) << "\n";
for (int i = 0; i < r; ++i) {
cin >> a >> b;
tot += b - arr[a];
arr[a] = b;
cout << tot / ((1 << n) + 0.0) << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, r, p2, sum, A[262145], i, x, y;
int main() {
ios::sync_with_stdio(false);
cin >> n >> r;
p2 = 1LL << n;
for (i = 1; i <= p2; i++) {
cin >> A[i];
sum += A[i];
}
cout << setprecision(10) << fixed << (1.0 * sum / p2) << "\n";
for (i = 1; i <= r; i++) {
cin >> x >> y;
x++;
sum -= A[x];
A[x] = y;
sum += A[x];
cout << setprecision(10) << fixed << (1.0 * sum / p2) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
scanf("%d%d", &n, &q);
n = 1 << n;
int* f = new int[n];
long long sum = 0;
for (int* it = f; it < f + n; ++it) {
scanf("%d", it);
sum += (long long)*it;
}
printf("%.10lf\n", (double)sum / n);
int z;
while (q--) {
scanf("%d", &z);
sum -= (long long)f[z];
scanf("%d", &f[z]);
sum += (long long)f[z];
printf("%.10lf\n", (double)sum / n);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, r;
cin >> n >> r;
int k = 1 << n;
vector<long long> b(k);
long long sum = 0;
for (int i = 0; i < k; ++i) {
cin >> b[i];
sum += b[i];
}
cout << fixed << setprecision(9);
cout << (double)sum / k << '\n';
for (int i = 0; i < r; ++i) {
int a, x;
cin >> a >> x;
sum -= b[a];
b[a] = x;
sum += b[a];
cout << (double)sum / k << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-8;
const long double PI = acos(-1.0);
const int MAXR = (1 << 18) + 20;
int n, r, c[MAXR];
long long sum;
void load() {
cin >> n >> r;
for (int i = 0; i < (1 << n); i++) {
cin >> c[i];
sum += c[i];
}
}
long double get() { return (long double)sum / (1 << n); }
void solve() {
cout << get() << '\n';
for (int i = 0; i < r; i++) {
int z, g;
cin >> z >> g;
sum = sum - c[z] + g;
c[z] = g;
cout << get() << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(6);
cout << fixed << showpoint;
load();
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
std::ios::sync_with_stdio(false);
int n, r;
cin >> n >> r;
vector<long long> vec(1 << n);
long long sum = 0;
for (auto &v : vec) {
cin >> v;
sum += v;
}
cout << sum / double(1 << n) << '\n';
int a, b;
for (size_t i = 0; i < r; ++i) {
cin >> a >> b;
sum += (b - vec[a]);
vec[a] = b;
cout << fixed << setprecision(10) << sum / double(1 << n) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int c[500000];
int main() {
int n, r;
scanf("%d%d", &n, &r);
int cnt = 1;
for (int i = 0; i < n; i++) {
cnt *= 2;
}
long long summ = 0;
for (int i = 0; i < cnt; i++) {
scanf("%d", &c[i]);
summ += c[i];
}
printf("%lf\n", (double)summ / cnt);
for (int i = 0; i < r; i++) {
int z, g;
scanf("%d%d", &z, &g);
summ -= c[z];
c[z] = g;
summ += c[z];
printf("%lf\n", (double)summ / cnt);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = (((1 << 30) - 1) << 1) + 1;
const int nINF = 1 << 31;
const int N = 1 << 18;
long long n, r, a[N], s = 0, k;
int main() {
ios::sync_with_stdio(false);
cout << fixed << setprecision(7);
cin >> n >> r;
k = 1 << n;
for (int i = 0; i < (k); i++) {
cin >> a[i];
s += a[i];
}
cout << s / (double)k << endl;
while (r--) {
int i, v;
cin >> i >> v;
s += (v - a[i]);
a[i] = v;
cout << s / (double)k << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int n, cq, a[N + 9];
long long sum;
void into() {
scanf("%d%d", &n, &cq);
for (int i = 0; i < 1 << n; ++i) {
scanf("%d", &a[i]);
sum += a[i];
}
}
void Get_ans() {
printf("%.10lf\n", 1.0 * sum / (1 << n));
for (; cq--;) {
int p, x;
scanf("%d%d", &p, &x);
sum -= a[p];
sum += a[p] = x;
printf("%.10lf\n", 1.0 * sum / (1 << n));
}
}
void work() { Get_ans(); }
void outo() {}
int main() {
int T = 1;
for (; T--;) {
into();
work();
outo();
}
return 0;
}
|
#include <bits/stdc++.h>
const int N = 18;
int n, r;
int a[1 << N];
long long sum;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.setf(std::ios::fixed);
std::cout.precision(12);
std::cin >> n >> r;
for (int i = 0; i < (1 << n); ++i) {
std::cin >> a[i];
sum += a[i];
}
std::cout << 1.0 * sum / (1 << n) << "\n";
while (r--) {
int x, v;
std::cin >> x >> v;
sum -= a[x];
a[x] = v;
sum += a[x];
std::cout << 1.0 * sum / (1 << n) << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 18 + 5;
int n, r;
double c[MAXN];
double ans, sum;
int main() {
cin >> n >> r;
int cnt = 1 << n;
for (int i = 0; i < cnt; i++) {
scanf("%lf", &c[i]);
sum += c[i];
}
ans = sum / cnt;
printf("%.7lf\n", ans);
int a, b;
while (r--) {
scanf("%d%d", &a, &b);
sum -= c[a];
c[a] = b;
sum += b;
ans = sum / cnt;
printf("%.7lf\n", ans);
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n, r, z, c[(1 << 18) + 10];
long long ans;
int main() {
scanf("%d%d", &n, &r);
for (int i = 0; i < (1 << n); i++) {
scanf("%d", c + i);
ans += c[i];
}
double w = 1 << n;
printf("%.10f\n", ans / w);
for (int i = 0; i < r; i++) {
scanf("%d", &z);
ans -= c[z];
scanf("%d", c + z);
ans += c[z];
printf("%.10f\n", ans / w);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename Args>
void kill(Args args) {
cout << args << "\n";
exit(0);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 1 << 19;
long double arr[N];
long double mul = 1;
int n, r;
void solve(int testnum) {
cin >> n >> r;
for (int i = 1; i <= n; i++) {
mul *= 0.5;
}
long double sum = 0;
for (int i = 0; i < (1 << n); i++) {
cin >> arr[i];
sum += arr[i];
}
cout << sum * mul << "\n";
for (int i = 1; i <= r; i++) {
int g;
long double x;
cin >> g >> x;
sum -= arr[g];
sum += x;
arr[g] = x;
cout << mul * sum << "\n";
}
}
void precompute() {}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(12);
int testcase = 1;
clock_t zzzx = clock();
precompute();
for (int i = 1; i <= testcase; i++) {
solve(i);
}
double elapsed_time = (double)(clock() - zzzx) / CLOCKS_PER_SEC;
cerr << "elapsed_time"
<< " = " << (elapsed_time) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll x[1 << 18];
void safeout(long long sum, long long m) {
using ld = long double;
long long f = sum / m;
long double s = ld(sum % m) / (ld)m;
if (f >= 10) {
s += sum % 10;
cout << f / 10 << (ld)s / (ld)m << endl;
} else {
cout << (ld)sum / (ld)m << endl;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
ll n, r;
cin >> n >> r;
ll m = 1 << n;
ll sum = 0;
for (int i = 0; i < m; i++) cin >> x[i], sum += x[i];
cout << fixed << setprecision(7);
safeout(sum, m);
for (int i = 0; i < r; i++) {
ll a, b;
cin >> a >> b;
sum -= x[a];
x[a] = b;
sum += x[a];
safeout(sum, m);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1 << 19];
int main() {
int n, r, p;
scanf("%d %d", &n, &r);
double ans = 0;
p = 1 << n;
for (int i = 0; i < p; i++) {
scanf("%d", &a[i]);
ans += a[i];
}
printf("%.6f\n", ans / p);
int z, g;
while (r--) {
scanf("%d %d", &z, &g);
ans -= a[z];
a[z] = g;
ans += a[z];
printf("%.6f\n", ans / p);
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n, r, c[maxn];
int main(void) {
cin >> n >> r;
int nm = (1 << n);
double rt = 0.0;
for (int i = 0; i < (1 << n); ++i) {
scanf("%d", &c[i]);
rt += double(c[i]) / nm;
}
printf("%.8f\n", rt);
for (int i = 0; i < r; ++i) {
int z, g;
scanf("%d%d", &z, &g);
rt -= (double(c[z] - g) / nm);
c[z] = g;
printf("%.8f\n", rt);
}
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 100005;
int main() {
int n;
long long r;
scanf("%d %lld", &n, &r);
n = 1 << n;
int c[n];
double sum = 0;
for (int i = 0; i < n; i++) scanf("%d", &c[i]), sum += c[i];
printf("%.6f\n", sum / n);
for (int i = 0; i < r; i++) {
int z, g;
scanf("%d %d", &z, &g);
sum = sum - c[z] + g;
c[z] = g;
printf("%.6f\n", sum / n);
}
}
|
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long inf = 1e18;
using namespace std;
long long int modpow(long long int x, long long int n) {
long long int res = 1;
while (n > 0) {
if (n & 1) res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
long long int power(long long int x, long long int n) {
long long int res = 1;
while (n > 0) {
if (n & 1) res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
long long int sq(long long int x1, long long int y1) {
return x1 * x1 + y1 * y1;
}
void always_ignore_function_name() {
int n, q;
cin >> n >> q;
std::vector<long long int> v(1 << n);
long double a = 0;
for (int i = 0; i < (1 << n); i++) {
cin >> v[i];
a += v[i];
}
cout << setprecision(10) << a / (1 << n) << endl;
while (q--) {
int x, y;
cin >> x >> y;
a += y - v[x];
v[x] = y;
cout << setprecision(10) << a / (1 << n) << endl;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t = 1, tt = 1;
while (tt <= t) {
always_ignore_function_name();
tt++;
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, flag = 0, t, a[1000000], ans = 0;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long double summ = 0.0;
cin >> n >> ans;
for (int i = 0; i < (1 << n); i++) {
cin >> a[i];
summ += a[i];
}
cout << fixed << setprecision(9) << (1.0l * summ / (1LL << n)) << '\n';
while (ans--) {
cin >> j >> k;
summ -= a[j];
a[j] = k;
summ += a[j];
cout << fixed << setprecision(9) << (1.0l * summ / (1LL << n)) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r;
scanf("%d %d", &n, &r);
double f[(1 << (n))], sum = 0;
for (int i = 0; i < (1 << n); ++i) scanf("%lf", &f[i]), sum += f[i];
printf("%0.12f\n", sum / (double)(1 << n));
for (int i = 0; i < r; ++i) {
int z;
double g;
scanf("%d %lf", &z, &g);
sum -= f[z];
f[z] = g;
sum += (double)g;
printf("%0.12f\n", sum / (double)(1 << n));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long N, R, c[262144 + 5], sum = 0;
struct idontknow {
long long z, g;
} r[262144 + 5];
void solution1() {
for (int i = 0; i < R; i++) {
if (0) cout << sum << endl;
printf("%6lf\n", (double)sum / (double)pow(2, N));
sum += r[i].g - c[r[i].z];
c[r[i].z] = r[i].g;
}
printf("%6lf\n", (double)sum / (double)pow(2, N));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> R;
for (int i = 0; i < pow(2, N); i++) cin >> c[i], sum += c[i];
for (int i = 0; i < R; i++) cin >> r[i].z >> r[i].g;
solution1();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, q;
cin >> n >> q;
n = (long long)(1 << n);
int ar[n];
double sum = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
sum += ar[i];
}
cout << fixed << setprecision(10);
cout << sum / n << endl;
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
sum += b - ar[a];
ar[a] = b;
cout << fixed << setprecision(10) << sum / n << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 1 << 18 | 3;
int n, q, a[N];
long long s;
int main() {
n = read(), q = read();
for (register int i = (0); i < (1 << n); i++) a[i] = read(), s += a[i];
printf("%lf\n", 1.0 * s / (1 << n));
while (q--) {
int x = read(), y = read();
s -= a[x], s += y, a[x] = y;
printf("%lf\n", 1.0 * s / (1 << n));
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, r;
cin >> n >> r;
ld d = pow(2, -n);
ll sum = 0;
vector<ll> c((1 << n));
for (int i = 0; i < (1 << n); ++i) {
cin >> c[i];
sum += c[i];
}
for (int i = 0; i < r; ++i) {
cout << fixed << setprecision(22) << sum * d << '\n';
int z, g;
cin >> z >> g;
ll old = c[z];
sum = sum - old + g;
c[z] = g;
}
cout << fixed << setprecision(22) << sum * d << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxpq = priority_queue<T, vector<T>, less<T>>;
template <typename T1, typename T2, typename H1 = hash<T1>,
typename H2 = hash<T2>>
struct pair_hash {
size_t operator()(const pair<T1, T2>& p) const {
return 31 * H1{}(p.first) + H2{}(p.second);
}
};
char _inputBuffer[4096 + 1], *_inputPtr = _inputBuffer, _outputBuffer[4096], _c,
_sign, *_tempInputBuf = nullptr, _numBuf[128],
_tempOutputBuf[128], _fill = ' ';
const char* _delimiter = " ";
int _cur, _outputPtr = 0, _numPtr = 0, _precision = 6, _width = 0,
_tempOutputPtr = 0, _cnt;
unsigned long long _precisionBase = 1000000;
void read(int& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(unsigned int& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(long long& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(unsigned long long& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_sign) (x) = -(x);
} while (0);
}
void read(double& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_c == '.')
for (double _div = 1.0;
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) += (_c - '0') / (_div *= 10))
;
if (_sign) (x) = -(x);
} while (0);
}
void read(long double& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
_sign = (x) == '-';
if (_sign)
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
for ((x) -= '0';
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) = (x)*10 + _c - '0')
;
if (_c == '.')
for (long double _div = 1.0;
(_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++))) >= '0';
(x) += (_c - '0') / (_div *= 10))
;
if (_sign) (x) = -(x);
} while (0);
}
void read(char& x) {
do {
do {
(x) = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while ((x) <= ' ');
} while (0);
}
void read(char* x) {
do {
_cur = 0;
do {
_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, 4096,
stdin)] = '\0',
*_inputPtr++));
} while (_c <= ' ');
do {
(x)[_cur++] = _c;
} while ((_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer,
1, 4096, stdin)] = '\0',
*_inputPtr++))) > ' ');
(x)[_cur] = '\0';
} while (0);
}
void read(string& x) {
do {
if (!_tempInputBuf) assert(0);
do {
_cur = 0;
do {
_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1,
4096, stdin)] = '\0',
*_inputPtr++));
} while (_c <= ' ');
do {
(_tempInputBuf)[_cur++] = _c;
} while ((_c = (*_inputPtr ? *_inputPtr++
: (_inputBuffer[fread(_inputPtr = _inputBuffer,
1, 4096, stdin)] = '\0',
*_inputPtr++))) > ' ');
(_tempInputBuf)[_cur] = '\0';
} while (0);
(x) = string(_tempInputBuf, _cur);
} while (0);
}
template <typename T, typename... Ts>
void read(T&& x, Ts&&... xs) {
read(x);
read(forward<Ts>(xs)...);
}
void write(bool x) {
do {
if (x)
(_tempOutputBuf[_tempOutputPtr++] = ('1'));
else
(_tempOutputBuf[_tempOutputPtr++] = ('0'));
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(int x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned int _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned int _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(unsigned int x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned int _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned int _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(long long x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned long long _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned long long _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(unsigned long long x) {
do {
if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
_cnt = 0;
for (unsigned long long _y = (-(x)); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
_cnt = 0;
for (unsigned long long _y = (x); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(double x) {
do {
if (std::isnan(x)) {
do {
int _slen = strlen("NaN");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("NaN"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if (std::isinf(x)) {
do {
int _slen = strlen("Inf");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("Inf"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
unsigned long long _I = (unsigned long long)(-(x));
unsigned long long _F = ((-(x)) - _I) * _precisionBase + (double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
unsigned long long _I = (unsigned long long)(x);
unsigned long long _F = ((x)-_I) * _precisionBase + (double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(long double x) {
do {
if (std::isnan(x)) {
do {
int _slen = strlen("NaN");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("NaN"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if (std::isinf(x)) {
do {
int _slen = strlen("Inf");
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = ("Inf"); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
} else if ((x) < 0) {
(_tempOutputBuf[_tempOutputPtr++] = ('-'));
unsigned long long _I = (unsigned long long)(-(x));
unsigned long long _F =
((-(x)) - _I) * _precisionBase + (long double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
} else {
unsigned long long _I = (unsigned long long)(x);
unsigned long long _F = ((x)-_I) * _precisionBase + (long double)(0.5);
if (_F >= _precisionBase) {
_I++;
_F = 0;
}
_cnt = 0;
for (unsigned long long _y = (_I); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < 1; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
(_tempOutputBuf[_tempOutputPtr++] = ('.'));
_cnt = 0;
for (unsigned long long _y = (_F); _y; _y /= 10, _cnt++)
_numBuf[_numPtr++] = '0' + _y % 10;
for (; _cnt < _precision; _cnt++) _numBuf[_numPtr++] = '0';
for (; _numPtr; (_tempOutputBuf[_tempOutputPtr++] = (_numBuf[--_numPtr])))
;
;
}
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(char x) {
do {
(_tempOutputBuf[_tempOutputPtr++] = (x));
int _tempLen = _tempOutputPtr;
for (int _i = 0; _i < (_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < _tempOutputPtr;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_tempOutputBuf[_i++]),
_outputPtr++))
;
_tempOutputPtr = 0;
for (int _i = 0; _i < (-_width - _tempLen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(char* x) {
do {
int _slen = strlen(x);
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = (x); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(const char* x) {
do {
int _slen = strlen(x);
for (int _i = 0; _i < (_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (const char* _p = (x); *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - _slen); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
void write(string& x) {
do {
for (int _i = 0; _i < (_width - (int)(x).length()); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
for (int _i = 0; _i < (int)(x).length();
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (x[_i++]),
_outputPtr++))
;
for (int _i = 0; _i < (-_width - (int)(x).length()); _i++)
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (_fill),
_outputPtr++);
} while (0);
}
template <typename T, typename... Ts>
void write(T&& x, Ts&&... xs) {
write(x);
for (const char* _p = _delimiter; *_p;
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = (*_p++),
_outputPtr++))
;
write(forward<Ts>(xs)...);
}
void writeln() {
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = ('\n'),
_outputPtr++);
}
template <typename... Ts>
void writeln(Ts&&... xs) {
write(forward<Ts>(xs)...);
(_outputBuffer[_outputPtr == 4096
? (fwrite(_outputBuffer, 1, _outputPtr, stdout),
_outputPtr = 0)
: _outputPtr] = ('\n'),
_outputPtr++);
}
void flush() {
do {
(fwrite(_outputBuffer, 1, _outputPtr, stdout), _outputPtr = 0);
fflush(stdout);
} while (0);
}
class IOManager {
public:
~IOManager() { flush(); }
};
unique_ptr<IOManager> _iomanager;
int N, Q;
long long A[(1 << 19)];
int main() {
_iomanager.reset(new IOManager());
do {
_precision = (9);
_precisionBase = 1;
for (int _i = 0; _i < (9); _i++, _precisionBase *= 10)
;
} while (0);
read(N, Q);
int NN = 1 << N;
long long sum = 0;
for (auto i = (0); i < (NN); i++) {
read(A[i]);
sum += A[i];
}
writeln(double(sum) / NN);
int z;
long long g;
for (auto i = (0); i < (Q); i++) {
read(z, g);
sum += g - A[z];
A[z] = g;
writeln(double(sum) / NN);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename Args>
void kill(Args args) {
cout << args << "\n";
exit(0);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 1 << 19;
long double arr[N];
int n, r;
void solve(int testnum) {
cin >> n >> r;
long double mul = 1 << n;
long double sum = 0;
for (int i = 0; i < (1 << n); i++) {
cin >> arr[i];
sum += arr[i];
}
cout << sum / mul << "\n";
for (int i = 1; i <= r; i++) {
int g;
long double x;
cin >> g >> x;
sum -= arr[g];
sum += x;
arr[g] = x;
cout << sum / mul << "\n";
}
}
void precompute() {}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(12);
int testcase = 1;
clock_t zzzx = clock();
precompute();
for (int i = 1; i <= testcase; i++) {
solve(i);
}
double elapsed_time = (double)(clock() - zzzx) / CLOCKS_PER_SEC;
cerr << "elapsed_time"
<< " = " << (elapsed_time) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(12);
int n, r;
cin >> n >> r;
int sz = (1 << n);
int c[sz];
long long sum = 0;
for (int i = 0; i < sz; i++) {
cin >> c[i];
sum += c[i];
}
double ans = (1.0 * sum) / sz;
cout << ans << "\n";
while (r--) {
int z, g;
cin >> z >> g;
sum += g;
sum -= c[z];
cout << (1.0 * sum) / sz << "\n";
c[z] = g;
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.