description
stringlengths
35
9.39k
solution
stringlengths
7
465k
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
/** * Created by Aminul on 11/14/2018. */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class C { public static void main(String[] args)throws Exception { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = in.ne...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; char ch[1000010]; int num[1000010]; int pre[1000010]; const long long mod = 1e9 + 7; int qpow(int a, int b) { long long ans = 1; long long ta = a, tb = b; while (tb) { if (tb & 1) ans = ans * ta % mod; tb >>= 1; ta = ta * ta % mod; } return (int)(ans %...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
//package math_codet; import java.io.*; import java.util.*; public class lets_do { InputReader in; PrintWriter out; Helper_class h; final long mod = 1000000007; public static void main(String[] args) throws java.lang.Exception{ new lets_do().run(); } void run() throws Exception{ ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAXINT = 2147483647; const long long MAXLL = 9223372036854775807LL; const int MAX = 400000; long long n, q, col, pref[MAX], l, r, sum, ans, t[MAX]; string s; int main() { cin >> n >> q; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '1') col++; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { long long n, q, a[100005]; int z[100005], o[100005]; scanf("%lld%lld", &n, &q); char s[100005]; scanf("%s", s); long long n2 = 1; z[0] = 0, o[0] = 0, a[0] = 0, a[1] = 1, n2 *= 2; for (long long i = 2; i < 100005; i++)...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int64_t MAXN = 1e5 + 134, M = 1e9 + 7; int64_t pr[MAXN], q[MAXN]; int64_t F(int64_t i) { if (i == 0) return 1; int64_t x = F(i / 2); if (i % 2 == 0) return (x * x) % M; else return (2 * x * x) % M; } int main() { ios_base::sync_with_stdio(false); c...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> long long qs[100005], po[20]; char a[100005]; int main() { long long n, q, l, r, us, num, ans, i; scanf("%lld %lld", &n, &q); scanf(" %s", &a[1]); for (i = 1; i <= n; i++) qs[i] = qs[i - 1] + a[i] - '0'; po[0] = 2; for (i = 1; i < 20; i++) po[i] = (po[i - 1] * po[i - 1]) % 100000000...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
n,q=map(int,raw_input().split()) s=raw_input() mod=1000000007 powers=[1 for i in range(n+1)] for i in range(1,n+1): powers[i]=(powers[i-1]*2)%mod cum=[0 for i in range(n+1)] for i in range(n): if s[i]=='0': cum[i+1]=cum[i]+1 else: cum[i+1]=cum[i] while q: l,r=map(int,raw_input().split())...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; public class Main { public static int mod = 1000000007; public static long pow(long x, long n) { if (n == 0) { return 1; } long x2 = x * x % mod; return pow(x2, n/2) * (n % 2 == 0 ? 1 : x) % mod; } public static...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int INFL = (int)1e9; const long long int INFLL = (long long int)1e18; const double INFD = numeric_limits<double>::infinity(); const double PI = 3.14159265358979323846; bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; } bool inrange(int x, int t) { return ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long power(long long n, long long x) { if (x == 0) return 1; if (x & 1) { return (n * (power((n * n) % 1000000007, x / 2))) % 1000000007; } else { return (power((n * n) % 1000000007, x / 2)) % 1000000007; } } void solve() { long long n; long long q;...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> const int mod = 1e9 + 7; using namespace std; long long bin_expm(long long a, int b) { long long ret = 1; while (b) { if (b & 1) ret = (ret * a) % mod; b = b >> 1; a = (a * a) % mod; } return ret; } long long madd(long long a, long long b) { return (a % mod + b % mod) % mod;...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHel...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long maxn = 100005; const long long mod = 1e9 + 7; long long sum[maxn << 2]; void build(long long rt, long long l, long long r) { if (l == r) { scanf("%1lld", &sum[rt]); } else { long long mid = (l + r) / 2; build(rt << 1, l, mid); build(rt <<...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long int no = 3e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 3e3 + 1; long long int ar[no], br[no]; long long int used[no]; long long int mul(long long int x, long long int y, long long int mod) { return ((x % mod) * (y % mod)) % mod; } long long int powwmod(long l...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.lang.*; public class c { public static final long MOD = (long)1000000007; public static void main(String[] args) { Scanner in = new Scanner(System.in); Locale.setDefault(Locale.US); int n = in.nextInt(); int q = in.nextInt(); int[] pref =...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.List; public class Main { private static final String NO = "NO"; private static fina...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import math if __name__ == '__main__': n,q = [int(x) for x in raw_input().split()] qq = str(raw_input()) s = [ int(x) for x in qq] prefix = [0]*n prefix[0]= s[0] temp = [0]*(n+1) temp[0]=1 mod = (pow(10,9)//1)+7 for i in range(1,n): prefix[i] += prefix[i-1] + s[i] temp[i] =( 2*(temp[i-1]%mod) )%mod ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.math.*; import java.util.*; public class C { public static void main(String[] args) throws NumberFormatException, IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); int q = sc.nextInt(); String s = sc.next()...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int main() { int n, q, i; scanf("%d %d", &n, &q); char x[100005]; long long poow[100005]; poow[0] = 1; for (i = 1; i <= 100004; i++) { poow[i] = (2 * poow[i - 1]) % 1000000007; } scanf("%s", x); int arr[100005]; arr[0] = x[0] - '0'; for (i = 1; i <...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() pref = [0 for i in range(n + 1)] for i in range(1, n + 1): pref[i] = pref[i - 1] + (s[i - 1] == '1') mod = 1000000007 ans = [] for i in range(q): a, b = map(int, input().split()) k = pref[b] - pref[a - 1]; N = b - a + 1 ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Solution { static long mod = (int)1e9 + 7 ; public static void main(String[] args) { int n = fs...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys mod=10**9+7 n,q=map(int,sys.stdin.readline().split()) S=sys.stdin.readline().strip() LR=[list(map(int,sys.stdin.readline().split())) for i in range(q)] LIST=[0] for s in S: if s=="1": LIST.append(LIST[-1]+1) else: LIST.append(LIST[-1]) def count(m,n,mod): return (pow(2,m,mod)-1)...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
//package Div2_520; import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class C { public static BufferedReader input; public static PrintWriter out; public StringTokenizer stoken = new StringTokenizer(""); public static void main(String[] args) throws IOException { ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.lang.reflect.Array; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner sc = new Scanner(System.in); public static void main(String[]...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split() n = int(n) q = int(q) s = r[1] p = [0] for v in range(n): p.append(p[v] + int(s[v])) ans = [] for k in range(q): a, b = r[k + 2].strip().split() a = int(a) b = int(b) l = b - a + 1 one = p[b] - p[a - 1] ans.app...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from __future__ import division from sys import stdin, stdout m = 10 ** 9 + 7 def write(x): stdout.write(str(x) + "\n") n, q = map(int, stdin.readline().split()) x = stdin.readline().rstrip("\n") sums = [0] * (n + 1) s = 0 for i, c in enumerate(x): if c == "1": s += 1 sums[i + 1] = s for lin...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, q; string s; int sz[100010], su[100010]; long long int sum[100010]; int main() { scanf("%d %d", &n, &q); cin >> s; for (int i = int(0); i < int(n); i++) { sz[i] = (s[i] == '0'); su[i] = (s[i] == '1'); if (i) sz[i] += sz[i - ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long int modular_exp(long long int A, long long int B, long long int C) { if (B == 0) return 1; if (B == 1) return A; long long int res = A; if (res > C) res = res % C; int counter = 2; while (counter < B) { res = res * res; if (res > C) res = res %...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
n,q=map(int,raw_input().split()) powers=[1]+[0]*n for i in xrange(n): powers[i+1]=(2*powers[i])%1000000007 s=raw_input() zeroes=[0]*(n+1) for i in xrange(n): zeroes[i+1]=zeroes[i]+1-int(s[i]) for i in xrange(q): l,r=map(int,raw_input().split()) guy=powers[r-l+1]-powers[zeroes[r]-zeroes[l-1]] guy%=10...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; constexpr int MAXN = 5 + 100000; constexpr int MOD = 7 + 1000000000; int oac[MAXN]; int add(int a, int b) { int ans = a + b; if (ans >= MOD) ans -= MOD; return ans; } int sub(int a, int b) { int ans = a - b; if (ans...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; import java.math.*; public class C{ static void precompute(int n){ pow2 = new long[n + 1]; pow2[0] = 1l; for(int i = 1; i <= n; i++) pow2[i] = (pow2[i - 1] * 2l) % mod; } public static void process(int testNumber){ int n = ni(...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split() n = int(n) q = int(q) s = r[1] p = [0] k = 0 for v in range(n): d = int(s[v]) k += (1 - d) p.append(k) for k in range(q): a, b = r[k + 2].strip().split() a = int(a) b = int(b) l = b - a + 1 zero = p[b] - p[a...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin, stdout def BigMod(a, b, m): if b == 0: return 1 % m x = BigMod(int(a), int(b / 2), int(m)) x = (x * x) % m if b % 2 == 1: return (x * a) % m return x n, m = map(int, stdin.readline().split()) ch = stdin.readline() base = [1 for i in range(n + 1)] pw = [1...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> bool debug = 1; const long long MOD = 1000000007; const double PI = acos(-1.0); const double eps = 1e-9; using namespace std; long long pot2[100100]; int s1[100100]; void pre() { pot2[0] = 1; for (int i = 1; i < 100100; i++) { pot2[i] = 2 * pot2[i - 1]; pot2[i] %= MOD; } } long lo...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const bool debug = false; const int maxn = 1e5 + 7; const int inf = 1e9 + 7; const long long mod = 1e9 + 7; int pre[maxn]; long long bp(long long a, long long p) { if (p == 0) return 1; if (p % 2) { return (bp(a, p - 1) * a) % mod; } else { long long re = bp(a...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int gcd(int f, int s) { if (s == 0) return f; else return gcd(s, f % s); } int const N = 1007006; long long const M = 1000 * 1000 * 1000 + 7; long double const ep = .000000000000000001; int arr[N]; long long pw[N]; int cul0[N], cul1[N]; int main() { int n, q; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.math.*; import java.io.*; public class CF1062C { long exp(long b, long e) { if(e == 0) return 1; long tmp = exp(b, e / 2); tmp = (tmp * tmp) % MOD; if((e & 1) == 1) tmp = (tmp * b) % MOD; return tmp; } final int MOD = (int) 1e9 + 7; public CF1062C() { FS scan = new FS();...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; import java.util.Collections; import java.util.Arrays; public class Codechef { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); long powers[]=new long[100001]; powers[0]=1; for(int i=1;...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
//package baobab; import java.io.*; import java.util.*; public class C { public static void main(String[] args) { Solver solver = new Solver(); } static class Solver { IO io; public Solver() { this.io = new IO(); try { solve(); ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
// Author @ BlackRise :) // // Birla Institute of Technology, Mesra// import java.io.*; import java.util.*; public class Banh_mi { static void Blackrise() { //The name Blackrise is my pen name... you can change the name according to your wish int n=ni(); ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys import math input=sys.stdin.readline def power(x, y, p) : res = 1 # Initialize result # Update x if it is more # than or equal to p x = x % p while (y > 0) : # If y is odd, multiply # x with result if ((y & 1) == 1) : res...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java....
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long add(long long x, long long y) { x += y; while (x >= 1000000007) x -= 1000000007; while (x < 0) x += 1000000007; return x; } long long mul(long long x, long long y) { return (x * 1ll * y) % 1000000007; } long long binpow(long long x, long long y) { long l...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; pair<int, int> pref[100005]; long long zeroes[1000005], ones[1000005]; int main() { int n, q; cin >> n >> q; ones[0] = 1; zeroes[0] = 1; for (int i = 1; i <= n; ++i) { ones[i] = ones[i - 1] * 2; ones[i] %= 1000000007; zeroes[i] = zeroes[i - 1] * 2; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int PS[100001]; long long fast_pow(long long a, long long b) { long long ret = 1; for (; b; b >>= 1) { if (b & 1) ret = (ret * a) % MOD; a = (a * a) % MOD; } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(NU...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { long long int r, i; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long int power(long long int x, long long int y, long long int mod) { long long int temp, ty, my; if (y == 0) retur...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin input = stdin.readline def power(a, b, mod): res = 1 while b: if b%2: res = (res*a)%mod b //= 2 a = (a*a)%mod return res%mod n, q = map(int, input().split()) s = list(map(int, input().strip())) MOD = 10**9+7 zeroes = ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#Wolve from sys import * m = 1000000007 n, q = map(int, stdin.readline().split()) a = stdin.readline() ans = [] t = [] count = 0 for i in a: if i == '1': count+=1 t.append(count) for _ in range(q): x,y=map(int,input().split()) if(x==1): p=t[y-1] else: p=t[y-1]-t[x-2] q=(y-x+1-p) s=pow(2,p+q,m)%m s=(((s%m...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; import static java.lang.Math.abs; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.sqrt; @SuppressWarnings("unchecked") public class P1062C { final static BigInteger TWO = BigInteger....
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int n, q, i, l, r, MOD = 1e9 + 7, t[100005 * 4], sum[100005]; int solve(int k, int len) { return (sum[len] - sum[len - k] + MOD) % MOD; } void build(int l, int r, int node) { if (l == r) { t[node] = getchar() - 48; return; } int mid = (l + r) >> 1; build(l, ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import math import sys from collections import defaultdict,Counter,deque,OrderedDict import bisect #sys.setrecursionlimit(1000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) def list2d(a, b, c): return [[c...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; string s; cin >> s; int ao[n + 3]; memset(ao, 0, sizeof ao); for (int i = 0; i < (int)s.size(); i++) { ao[i] += (s[i] == '1'); if (i) ao[i] += ao[i - 1]; } long long sp[100001], asp[100001]; sp[0] = 1; asp[...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); cerr << "Completed in " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds\n"; } const long long INF = 1e9; const long long N = 1e5 + 5; const long long MOD = 1e9 + 7; long long ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split() n = int(n) q = int(q) s = r[1] p = [0] k = 0 for v in range(n): d = int(s[v]) k += (1 - d) p.append(k) for k in range(q): a, b = r[k + 2].strip().split() a = int(a) b = int(b) l = b - a + 1 zero = p[b] - p[a...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* abhi2601 */ public class Practice implements Runnable{ final static long mod = (long)1e9 + 7; public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int q = scan.nextInt(); String S = scan.next(); int[] ones = new int[n+1]; int[] zeros = new int[n+1]; int numOfOnes = 0; int numOFZeros = 0; for (int ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
mod = 1000000007 n, q = list(map(int,input().split())) arr = list(map(int,list(input()))) s = 0 preSum = [] for i in range(n): s+=arr[i] preSum.append(s) ans = [] for i in range(q): l,r = list(map(int,input().split())) am = r-l+1 s = preSum[r-1] - preSum[l-1] + arr[l-1] perfect = pow(2,am,mod) ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 100; const int MOD = 1e9 + 7; int Pow(int a, int k, int p) { int ans = 1; while (k) { if (k & 1) ans = 1ll * ans * a % p; k >>= 1; a = 1ll * a * a % p; } return ans; } int pre1[maxn]; int pre0[maxn]; int main() { int n, q; c...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys def numIN(): return(map(int,sys.stdin.readline().strip().split())) MOD = 10**9+7 n,q = numIN() l = [int(i) for i in input()] pre = [] s = 0 for i in l: s+=i pre.append(s) for i in range(q): l,r = numIN() l-=1 r-=1 if l!=0: one = pre[r]-pre[l-1] zero = r-l+1-one ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long int K = 1e9 + 7; long long int mu[100005]; int a[100005]; int s[100005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); mu[0] = 1; for (int i = 1; i <= 100000; i++) { mu[i] = mu[i - 1] * 2ll % K; } int n, q; cin >> n >> q; for (int ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class temp4 { static class FastReader { BufferedReader br; Stri...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.math.BigInteger; import java.util.StringTokenizer; public class Banhi { static long modPow(int a, int e, int mod) { a %= mod; long res = 1; while(e > 0) { if((e & 1) == 1) res =(1l*res * a) % mod; a = (int)((1...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin, stdout MOD = pow(10, 9) + 7 n, q = map(int, raw_input().strip().split()) s = list(raw_input().strip()) pre = [0 for i in xrange(n + 1)] for i in xrange(1, n + 1): pre[i] = pre[i - 1] + int(s[i - 1] == '1') inp = stdin.readlines() out = [] for line in inp: l, r = map(int, line.strip().spl...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner scn=new Scanner(System.in); BufferedWriter output = new BufferedWriter( new OutputStreamWriter(System.out)); int p=1000000000+7; int[] arr=new in...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split(' ') n = int(n) q = int(q) s = r[1] p = [0] for v in range(n): p.append(p[v] + int(s[v])) ans = [] for k in range(q): a, b = r[k + 2].strip().split(' ') a = int(a) b = int(b) l = b - a + 1 one = p[b] - p[a - 1] a...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const long long mod = 1e9 + 7; long long m[maxn], pre[maxn]; char s[maxn]; int sum[maxn]; int main() { int n, q; scanf("%d%d", &n, &q); scanf("%s", s + 1); m[0] = 1; long long base = 1; for (int i = 1; i <= n; i++) { base *= 2; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int dx4[] = {0, 0, -1, 1}; int dy4[] = {-1, 1, 0, 0}; int dx8[] = {0, 0, -1, 1, -1, -1, 1, 1}; int dy8[] = {-1, 1, 0, 0, -1, 1, -1, 1}; int knightx[] = {-1, 1, -2, 2, -2, 2, -1, 1}; int knighty[] = {-2, -2, -1, -1, 1, 1, 2, 2}; template <typename T> T in() { char ch; T ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long int INFL = 1e18; const int MAX_N = 1e5; const long long int MOD = 1e9 + 7; long long int cntsum[MAX_N + 2]; long long int psum[MAX_N + 2]; long long int get_sum(int l, int r, long long int* arr) { if (l == 0) return arr[r]; else ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long ps[100005]; long long p2[100005]; inline long long mathh(long long x, long long n) { n -= x; long long ans = (p2[x] - 1) % mod; ans += ans * (p2[n] - 1); return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.t...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public st...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long pow_2[200010]; int a[200010]; int b[200010]; int main() { pow_2[0] = 1; for (long long i = 1; i <= 200000; i++) { pow_2[i] = (pow_2[i - 1] * 2) % mod; } fill(a, a + 100010, 0); fill(b, b + 100010, 0); int n, q; scanf("%d%...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> long long i, j, k, n, m, x, z, q, a[100009], pw[100009]; using namespace std; int main() { std::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); string s; cin >> x >> q >> s; for (i = 0; i < x; i++) { if (s[i] == '0') a[i + 1] = a[i] + 1; else a[i + 1] = a[...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int MAX = 1e5 + 10; const long long BIG = 1e11 + 10; const double eps = 1e-6; const double PI = 3.14159; const long long mod = 1000000007; int n, q; string s; int one[MAX], zero[MAX]; long long mypow(long long a, long long n, long long MOD) ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const long long mod = 1e9 + 7; int cnt[maxn][2]; long long powMod(long long a, long long b) { long long sum = 1; a %= mod; while (b > 0) { if (b % 2 == 1) sum = (sum * a) % mod; b /= 2; a = (a * a) % mod; } return sum; } i...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import * m = 1000000007 n, q = map(int, stdin.readline().split()) a = stdin.readline() ans = [] t = [] count = 0 for i in a: if i == '1': count+=1 t.append(count) for _ in range(q): x,y=map(int,input().split()) if(x==1): p=t[y-1] else: p=t[y-1]-t[x-2] q=(y-x+1-p) s=pow(2,p+q,m)%m s=(((s%m)-(pow(...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5 + 7; const long long mod = 1e9 + 7; string a; long long a1[maxn]; long long counting(long long a, long long b) { long long sum = 1; while (a) { if (a & 1) sum = (b * sum) % mod; b = (b * b) % mod; a >>= 1; } return sum % mod; }...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; using ll = long long; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007ll; int n, q; char s[100100]; long long count0[100100]; long long count1[100100]; long long QPow(long long x, long long n) { long long ret = 1; long long tmp = x % MOD; while (n) { if (n & 1) { ret = (ret * tmp) % MOD; } ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1e5 + 7; const int MOD = 1e9 + 7; const int MAX = 1 << 30; int n, q, l, r, dp[LIMIT], f[LIMIT]; char c; int main() { scanf("%d %d\n", &n, &q); f[0] = 1; for (int i = 0; i < n; i++) { scanf("%c", &c); dp[i + 1] = dp[i] + (c - '0'); f[i + 1...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from bisect import bisect_right as br from bisect import bisect_left as bl from collections import defaultdict import sys import math MAX = sys.maxsize MOD = 10**9+7 MAXN = 10**6+10 def isprime(n): n = abs(int(n)) if n < 2: return False if n == 2: return True if not n & 1: ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
def beki(a,b): waru=10**9+7 ans=1 while(b>0): if(1 & b): ans= ans * a %waru b >>= 1 a=a * a % waru return ans n,m=map(int,input().split()) s=input() ans=[] waru=10**9+7 ru=[0]*(n+1) b=[1]*(n+1) for i in range(n): ru[i+1]=ru[i]+int(s[i]) b[i+1]=(b[i]*2)%waru ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.Arrays; import java.util.Scanner; /** * Created by Jamie on 2/14/2019. */ public class Bahnmi { public static int MODULUS = 1_000_000_007; public static void main(String[] args) { Scanner scan = new Scanner(System.in); FTree ftree = new FTree(100_000); int n = scan...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; public class Task { public static void main(String[] args) throws IOException { new Task().go(); } PrintWriter out; Reader in; BufferedReader br; Task() throws IOException { try { //br = new BufferedReader( new FileReader("...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; void smain(); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(12); smain(); } vector<long long> pf; const long long N = 1 << 17; const long long M = 1e9 + 7; long long cnt[N]; inline long long MOD(long long v) {...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Objects; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author P...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long n, q, p[100005]; string s; long long expo(long long base, long long exponent, long long mod) { long long ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } retu...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.math.*; import java.io.*; public class CF1062C { final int MOD = (int) 1e9 + 7; public CF1062C() { FS scan = new FS(); PrintWriter out = new PrintWriter(System.out); long[] pt = new long[100_001]; pt[0] = 1; for(int i = 1 ; i < 100_001 ; i++) pt[i] = (pt[i - 1] << 1) % MO...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author real */ public class Main ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
//package graphs; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class PW { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; import static java.lang.Math.*; public class Main { FastScanner in; PrintWriter out; void run() { in = new FastScanner(); out = new PrintWriter(System.out); problem(); out.close(); } clas...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int dcmp(long double n, long double y) { return fabs(n - y) <= 1e-9 ? 0 : n < y ? -1 : 1; } const int MAX = 1e5 + 10; const long long MOD = 1e9 + 7; long long prefix[MAX][2], sum_of_pow[MAX], n, q; string in; long long POW_M(long long a, long long p, long long m = MOD) { ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
n,m=map(int,input().split()) t=list(map(int,list(input()))) p=[0]+t[:] mod=10**9+7 o=[] for i in range(n): p[i+1]+=p[i] for _ in range(m): l,r=map(int,input().split()) a=p[r]-p[l-1] b=(r-l+1)-a o.append(str((pow(2,a+b,mod)-pow(2,b,mod))%mod)) print('\n'.join(map(str,o)))
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10; const long long mod = 1e9 + 7; long long a[maxn]; long long quick(long long a, long long n) { long long ans = 1; while (n != 0) { if (n % 2 == 0) a = a % mod * a % mod, n = n / 2; else ans = a % mod * ans % mod, n--; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHe...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import javafx.util.Pair; import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(System.out); Main mm = new Main(); mm.problemC(new Input(new BufferedReader(new InputStreamRe...