forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
103 lines (83 loc) · 2.73 KB
/
D.cpp
File metadata and controls
103 lines (83 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <bits/stdc++.h>
#define int long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int) (x).size())
using namespace std;
int my_round(double x) {
if (x < 0) return -my_round(-x);
return (int) (x + 1e-3);
}
const double PI = acos((double) -1.0);
typedef complex<double> cplex;
const int MN = 1000111;
int rev[MN];
cplex wlen_pw[MN], fa[MN], fb[MN];
void fft(cplex a[], int n, bool invert) {
for (int i = 0; i < n; ++i) if (i < rev[i]) swap (a[i], a[rev[i]]);
for (int len = 2; len <= n; len <<= 1) {
double alpha = 2 * PI / len * (invert ? -1 : +1);
int len2 = len >> 1;
wlen_pw[0] = cplex(1, 0);
cplex wlen(cos(alpha), sin(alpha));
for (int i = 1; i < len2; ++i) wlen_pw[i] = wlen_pw[i-1] * wlen;
for (int i = 0; i < n; i += len) {
cplex t, *pu = a+i, *pv = a + i + len2,
*pu_end = a + i + len2, *pw = wlen_pw;
for (; pu != pu_end; ++pu, ++pv, ++pw) {
t = *pv * *pw;
*pv = *pu - t;
*pu += t;
}
}
}
if (invert) REP(i, n) a[i] /= n;
}
void calcRev(int n, int logn) {
REP(i, n) {
rev[i] = 0;
REP(j, logn) if (i & (1 << j)) rev[i] |= 1 << (logn - 1 - j);
}
}
void mulpoly(int a[], int b[], ll c[], int na, int nb, int &n) {
int l = max(na, nb), logn = 0;
for (n = 1; n < l; n <<= 1) ++logn;
n <<= 1; ++logn;
calcRev(n, logn);
REP(i,n) fa[i] = fb[i] = cplex(0);
REP(i,na) fa[i] = cplex(a[i]);
REP(i,nb) fb[i] = cplex(b[i]);
fft(fa, n, false);
fft(fb, n, false);
REP(i,n) fa[i] *= fb[i];
fft(fa, n, true);
REP(i,n) c[i] = (ll)(fa[i].real() + 0.5);
}
int a[MN], b[MN], c[MN];
string s;
#undef int
int main() {
#define int long long
ios :: sync_with_stdio(0); cin.tie(0);
freopen("duel.in", "r", stdin);
freopen("duel.out", "w", stdout);
while (cin >> s) {
int n = SZ(s);
REP(i,n) a[i] = s[i] - '0';
REP(i,n) b[i] = a[i];
int nc;
mulpoly(a, b, c, n, n, nc);
int res = 0;
REP(k,n) if (s[k] == '1') {
res += (c[k + k] - 1) / 2;
}
cout << res << endl;
}
}