description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | import java.io.*;
import java.util.*;
public class Pr103B {
public static void main(String[] args) throws IOException {
new Pr103B().run();
}
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokeniz... |
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class graph {
static ArrayList<Integer>[] adjList... |
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | def findset(n):
global parent
if parent[n] != n:
parent[n] = findset(parent[n])
return parent[n]
def union(u, v):
global parent
a = findset(u)
b = findset(v)
if a == b:
return 1
parent[a] = b
return 0
count = 0
n, m = map(int,input().split())
x = []
y = []
parent = list(range(n+1))
for _ in... |
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | import java.util.LinkedList;
import java.util.Scanner;
public class Cthulhu {
LinkedList <Integer> [] list ;
boolean [] visited ;
int [] parent ;
boolean ans ;
boolean first ;
public Cthulhu (){
Scanner stream = new Scanner (System.in);
int v = stream.nextInt() ;
int e = stream.nextInt() ;
list = new Li... |
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... | //make sure to make new file!
import java.io.*;
import java.util.*;
public class C520{
public static long MOD = 1000000007L;
public static void main(String[] args)throws IOException{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System... |
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
r = sys.stdin.readlines()
n, q = r[0].split(' ')
n = int(n)
q = int(q)
s = r[1]
c = [0] * (n + 1)
for i in range(n):
c[i + 1] = c[i] + (s[i] == '1')
p2 = [1] * (2 * n + 1)
for i in range(1, 2 * n + 1):
p2[i] = p2[i - 1] * 2 % MOD
out = []
for qq in range(q):
a, b = r[qq + 2].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.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main
{
static long mod=(long)(1e+9 + 7);
//s... |
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 n, t, i, j, arr[1000004], a, b, store, arr1[1000004], ans,
final[1000004], ans1;
long long aa, mod = 1000000007, zero[1000004], one[1000004], zer, on,
final1[1000004];
char name[1000004];
using namespace std;
int main() {
scanf("%lld %lld", &n, &t);
scanf("%s", 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 int MAX = 1e5 + 5;
const int BASE = 1e9 + 7;
int n, q;
bool a[MAX];
int f[MAX];
int num[MAX][2];
int Power(int x, int y) {
if (y == 0) return 1;
int tmp = Power(x, y / 2);
if (y % 2) return (1LL * ((1LL * tmp * tmp) % BASE) * x) % BASE;
return (1LL * tmp * tmp... |
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 INF = 1e18 + 322;
const long long maxn = 1e5 + 228;
const long long MOD = 1e9 + 7;
long long n, q, pr[maxn];
long long bin_pow(long long a, long long n) {
if (n == 0) return 1;
if (n & 1) {
return (bin_pow(a, n - 1) * a) % MOD;
} else {
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... | import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;
public class banh_mi {
public static void main(String[] args) throws Exception {
new banh_mi().run();
}
public 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 MOD = 1e9 + 7;
const int MAXN = 100005;
long long q, n, l, r, ans;
char c;
long long sum[MAXN], sumPow[MAXN];
void init() {
sumPow[0] = 1;
long long temp = 1;
for (int i = 1; i <= MAXN; i++) {
temp = temp * 2 % MOD;
sumPow[i] = (sumPow[i - 1] % 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;
long long calc_power(long long x) {
if (x == 0) {
return 1L;
}
long long t = calc_power(x / 2L);
if (x % 2) {
return ((t * t) * 2L) % 1000000007L;
}
return ((t * t)) % 1000000007L;
}
int main() {
long long n, q;
cin >> n >> q;
vector<long long> arr... |
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;
vector<long long int> two(100000 + 2, 1);
long long int mod = 1000000000 + 7;
void p() {
long long int i;
for (i = 1; i <= 100000; i++) {
two[i] = (2 * two[i - 1]) % mod;
}
for (i = 1; i <= 100000; i++) {
two[i] = (two[i] + two[i - 1]) % mod;
}
}
void solv... |
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,input().split())
a = input()
sums = []
degrees = [1,2]
res = []
d = 2
if (a[0] == "1"):
s = 1
else:
s = 0
sums.append(s)
for i in range(1,n):
if (a[i] == "1"):
s += 1
d = (d*2)%1000000007
sums.append(s)
degrees.append(d)
for i in range(0,q):
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;
const int maxN = 1e6 + 5, MOD = 1e9 + 7, eps = 1e-7, INF = 1e9;
const double PI = acos(-1);
int n, q, a, b;
string str;
int acum[maxN];
long long mulmod(long long a, long long b) {
long long ret = 0;
while (b) {
if (b & 1) ret = (ret + a) % MOD;
b >>= 1, a = (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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int val[maxn];
long long poww[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
string t;
cin >> t;
poww[0] = 1;
f... |
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())
l = raw_input()
cnt1, cnt0 = [0]*(n+1), [0]*(n+1)
mod = 10**9 + 7
for i in range(len(l)):
if l[i] == '1':
cnt1[i+1] = cnt1[i] + 1
cnt0[i+1] = cnt0[i]
else:
cnt0[i+1] = cnt0[i] + 1
cnt1[i+1] = cnt1[i]
pow2 = [1]
for i in range(1, 10**5 + 10):
pow2.append((2*pow2[-1])%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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
long long fastexpom(long long a, long long b, long long m) {
long long res = 1;
while (b > 0) {
if (b % 2 == 1) res = (((res) % m) * ((a) % m)) % m;
a = (((a) % 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... | 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
ruiseki=[0]*(n+1)
bekij=[1]*(n+1)
for i in range(n):
ruiseki[i+1]=ruiseki[i]+int(s[i])
b... |
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())
inp = raw_input()
arr = []
for i in inp:
arr.append(int(i))
mod = 10**9 + 7
twos = [1]
for i in range(1, 10**5 + 1):
twos.append((twos[-1] * 2)%mod)
ones = [0] * (n+1)
danger = False
for i in range(n):
if arr[i] == 1:
ones[i+1] = ones[i] + 1
else:
ones[i+1] = ones[i]
if... |
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 = 1e9 + 7;
const long long N = 100100;
char a[N];
long long sum[N];
long long qm(long long a, long long b) {
long long ans = 1;
while (b) {
if (b % 2) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b /= 2;
}
return ans % 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.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.Arrays;
import java.util.ArrayList;... |
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>
char s[233333];
int n, q, pre[233333];
int pow(int a, int k) {
int ans = 1;
while (k) {
if (k & 1) ans = 1ll * ans * a % 1000000007;
k >>= 1;
a = 1ll * a * a % 1000000007;
}
return ans;
}
int main() {
scanf("%d%d", &n, &q);
scanf("%s", s + 1);
for (int i = 1; i <= n; 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 java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
public class PROG4{
private static InputReader sc;
private static PrintWriter pw;
private static TreeSet<Integer> primeSet;
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... | 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... | #include <bits/stdc++.h>
using namespace std;
char buf[100000], *p1, *p2;
int rd() {
int x = 0;
char s =
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++);
while (s < '0' || s > '9')
s = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdi... |
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
n,q=map(int,input().split())
mod=1000000007
o=[]
s=[]
r=m=0
a=input()
for i in a:
if i=='0':
r+=1
else:
m+=1
o.append(r)
s.append(m)
z=[1]
#print(o)
for i in range(100000):
z.append((z[-1]*2)%mod)
for j in range(q):
l,r=(int(j) for j in stdin.readline... |
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;
template <typename T, typename U>
istream &operator>>(istream &in, pair<T, U> &data) {
in >> data.first >> data.second;
return in;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &vect) {
for (unsigned i = 0; i < vect.size(); i++) {
in >> vect[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 java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.ma... |
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 {
static long oo = 1_000_000_007;
static long add(long a, long b) {
return (a+b)%oo;
}
static long negate(long a) {
return (oo-a)%oo;
}
static long mult(long a, long b) {
return (a*b)%oo;
}
static long pow(long a, long p) {
if(p == 0) return 1;
if(p == 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.util.StringTokenizer;
public class C {
public static void main(String[] args) throws IOException {
try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
int n = input.nextInt();
int q = input.nextInt();
... |
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 All_in_all;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
/**
* Created by nikitos on 25.08.17.
*/
public class simvoli {
public StreamTokenizer t;
private final int INF = Integer.MAX_VALUE / 2;
private int mod = 1000000000 + 7;
public int nextInt() throws IOExcept... |
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 MAX = 1e5 + 5;
const long long MOD = 1e9 + 7;
int n, q, arr[MAX];
long long pp[MAX];
long long pro(int cnt, int len) {
long long ans = pp[cnt] - 1;
ans += (pp[len - cnt] - 1) * ans;
return (ans % MOD + MOD) % MOD;
}
int main() {
ios_base::sync_with_stdio(0... |
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 *
mod = int(1e9 + 7)
sum0 = [0]*100005
sum1 = [0]*100005
f = [0]*100005
f[1] = 1
res = 1
for i in range(2,100001):
res = (res * 2) % mod
f[i] = (f[i-1] + res) % mod
n,q = map(int,stdin.readline().split())
s = stdin.readline()
for i in range(len(s)):
sum0[i+1] = sum0[i]
sum1[i+1] = sum... |
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 B {
public static void main (String[] args) { new B(); }
public B() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
System.err.println("");
int MAX = 100100;
int MOD = (int)1e9+7;
int[] pows = new int[MAX];
pows[0... |
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.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
// Complete the sockMerchant function below.
private static final Scanner scanner = new Scanner(System.in);
public sta... |
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 org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import java.io.*;
import java.math.*;
import java.util.*;
// author @mdazmat9
public class CodeForces_C {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int q=sc.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... | import java.io.*;
import java.util.*;
public class BanhMi
{
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
long MOD = 1000000007;
public void go()
{
int numParts = 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 int mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
int N, Q;
char S[MAXN];
int one[MAXN];
long long pw(long long a, long long p) {
if (p == 0) return 1;
if (p == 1) return a;
long long t = pw(a, p / 2);
t = (t * t) % mod;
if (p & 1) t = (t * a) % mod;
return 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.*;
import java.util.*;
public class Main
{
private void solve()throws Exception
{
int n=nextInt();
int q=nextInt();
String s=nextLine();
int ones[]=new int[n+1];
int zeroes[]=new int[n+1];
for(int i=1;i<=n;i++)
{
ones[i]=ones[i-1]+(s.charAt(i-1)=='1'?1:0);
zeroes[i]=zeroes[i-1]+(s... |
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() {
long long n, q;
cin >> n >> q;
vector<long long> powe(n + 1, 0);
powe[0] = 1;
for (long long i = 1; i <= n; i++) powe[i] = (powe[i - 1] * 2) % 1000000007;
vector<long long> A(n, 0), pre(n, 0);
string s;
cin >> s;
for (long long i = 0; i < n; 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... | # -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 11/19/18
"""
N, M = map(int, input().split())
A = [int(x) for x in input()]
memo = [-1] * (N+1)
def pow(n):
if n == 0:
return 1
if n < 30:
return 1 << n
if memo[n] >= 0:
return memo[n]
half = pow(n // 2)
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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* @author khokharnikunj8
*/
public class Main {
public static void main(String[] args) {
... |
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 inf = 1e18 + 5LL;
const long long mod = 1e9 + 7LL;
void solve();
void ITO();
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ITO();
long long t = 1;
while (t--) solve();
return 0;
}
const long long N = (1e7 + 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.util.Scanner;
public class Main {
static long mod = 1000000007;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int q = in.nextInt();
in.nextLine();
long[] pot = initTwoPot(n);
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... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y, long long p) {
long long r = 1;
x = x % p;
while (y > 0) {
if (y & 1) r = (r * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return r;
}
int main() {
ios_base::sync_with_stdio(false);
... |
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 sum[1000100];
long long ans[1000100];
int main() {
ans[0] = 1;
for (int i = 1; i < 1000100; i++) {
ans[i] = ans[i - 1] * 2;
ans[i] %= MOD;
}
int n, q;
cin >> n >> q;
string s;
cin >> s;
for (int i = 1; i <= s.size(); 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
from math import floor, ceil
#sys.stdin = open('input.txt', 'r')
inp = lambda: sys.stdin.readline().strip()
MOD = 1e9 + 7
n, q = map(int, inp().split())
s = inp()
d = [0] * (n + 1)
pwr2 = [0] * (n + 1)
pwr2[0] = 1
for i in range(1, n + 1):
pwr2[i] = int(((pwr2[i - 1] * 2) % MOD))
for i in range(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... | for _ in range(1):
n,q = map(int,input().split())
s = input()
# s = s[:-2]
# s = s[1:]
s = list(s)
# print(s)
zeros = [0]*n
ones = [0]*n
if (s[0]=='1'):
ones[0]=1
else:
zeros[0]=1
for i in range(1,n):
ones[i]+=ones[i-1]
zeros[i]+=zeros[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... | import java.io.*;
import java.util.*;
public class TaskC
{
public static void main(String[] args)
{
new TaskC(System.in, System.out);
}
static class Solver implements Runnable
{
static final long MOD = (long) 1e9 + 7;
int n, q;
char[] s;
int[] arr;
long[] tree;
BufferedReader in;
// InputReader 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 java.util.*;import java.io.*;import java.math.*;
public class Main
{
public static void process()throws IOException
{
int n=ni(),q=ni();
char arr[]=(" "+nln()).toCharArray();
int pref_0[]=new int[n+2],pref_1[]=new int[n+2];
for(int i=1;i<=n;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 int MOD = 1e9 + 7;
class segTree {
private:
vector<int> seg;
public:
segTree(int n = 0) { seg.assign(4 * n + 7, 0); }
void build(int k, int l, int r, int x, int val) {
if (x < l || r < x) return;
if (l == r) {
seg[k] = val;
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;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
char s[N];
int num[N];
long long quickpow(long long a, long long m) {
long long res = 1;
long long b = a;
while (m) {
if (m & 1) res = res * b % mod;
b = b * b % mod;
m >>= 1;
}
return res;
}
int 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... |
import java.io.*;
import java.util.*;
/**
*
* @author akash_2ehuikg
* Coding is love <3!
*/
public class C {
public static void main(String args[]) {
try {
int n=nextInt();
int q=nextInt();
String s=" "+next();
int A[]=new int[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... | #include <bits/stdc++.h>
using namespace std;
vector<long long> _data;
long long a, q, b, k, l, r, n, m, tmp, ans = 0;
template <int m>
struct modint {
long long x;
modint() : x(0) {}
modint(long long arg) {
arg %= m;
if (arg < 0)
x = arg + m;
else
x = arg;
}
modint& operator+=(const 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... | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const long long mod = 1e9 + 7;
const int N = 1e5 + 10;
char s[N];
long long sum[N], a[N];
int main() {
int n, q;
cin >> n >> q;
cin >> s + 1;
a[0] = 1;
for (int i = 1; i <= n; ++i) a[i] = 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;
void codeforces_520_A() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int ans = 0;
if (n == 1) {
printf("0");
return;
} else if (n == 2) {
if (a[0] == 1 && a[1] == 2) {
printf("1");
} else 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
r = sys.stdin.readlines()
M = 10 ** 9 + 7
n, q = r[0].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].split(' ')
a = int(a)
b = int(b)
l = b - a + 1
one = p[b] - p[a - 1]
v = (pow(2, l, 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... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
if (b < 0) return 0;
long long ret = 1;
a %= mod;
while (b) {
if (b & 1) ret = (ret * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return ret;
}
char num[10000001];
int a[1000001][3];
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 sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=list(input().rstrip())
mod=10**9+7
for i in range(n):
s[i]=int(s[i])
cnt=[0]*(n+1)
for i in range(n):
if s[i]==1:
cnt[i+1]+=1
for i in range(1,n+1):
cnt[i]+=cnt[i-1]
p=[0]*(10**6+1)
p[0]=1
for i in range(1,10**6+1):
p[i]=(p[i-1]*2)%mod
for _... |
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 = list(map(int, input().split()))
a = input()
Q = []
for _ in range(q):
Q.append(list(map(int, input().split())))
d = [0]
ab = 0
for i in a:
if i == '1':
ab += 1
d.append(ab)
mod = int(1e9 + 7)
p = [1]
i = 1
for _ in range(n):
i = (i*2)%mod
p.append(i)
for l,r in Q:
y = r-l + 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 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 i in range(n):
d = int(s[i])
k += (1 - d)
p.append(k)
ans = []
for k in range(q):
a, b = r[k + 2].strip().split()
a = int(a)
b = int(b)
l = b - a + 1
zero = 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... | //package ;
import java.io.*;
import java.util.*;
public class C
{
static int freq[][],n;
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner();
PrintWriter pw = new PrintWriter(System.out);
n=sc.nextInt();int q=sc.nextInt();
freq=new int[2][n];
char c[]=sc.nextLine().toC... |
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.*;
import static java.lang.Math.*;
/* spar5h */
public class cf3 implements Runnable {
public void run() {
InputReader s = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = s.nextInt(), q = s.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;
vector<long long> tt;
void pre() {
tt.push_back(0);
long long temp = 0;
for (int i = 1; i <= 100005; i++) {
temp += tt[i - 1] + 1;
temp %= 1000000007;
tt.push_back(temp);
}
}
long long power(long long x, long long y) {
long long res = 1;
while (y > 0... |
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 = 1e9 + 7;
const int maxm = 1e5 + 10;
long long ar[maxm], data[maxm];
char cr[maxm];
long long quik(long long a, long long b) {
long long sum = 1;
while (b) {
if (b & 1) {
sum = (sum * a) % mod;
}
a = a % mod;
a = (a * a) % 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 inf = INT_MAX;
const long long int INF = LLONG_MAX;
const long long int mod = 1e9 + 7;
long long int powfast(long long int x, long long int y) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % 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 double PI = acos(-1.0);
const double eps = 1e-8;
const int inf = 1000000000;
const long long infLL = 1000000000000000000;
long long MOD = 1000000000;
inline bool checkbit(long long n, int i) { return n & (1LL << i); }
inline long long setbit(long long n, int i) { 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 sys
r = sys.stdin.readlines()
M = 10 ** 9 + 7
n, q = map(int, r[0].strip().split())
s = r[1]
p = [0]
k = 0
for i in range(n):
d = int(s[i])
k += d
p.append(k)
ans = []
for k in range(q):
a, b = map(int, r[k + 2].strip().split())
l = b - a + 1
one = p[b] - p[a - 1]
zero = l - one
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 sys
input = sys.stdin.readline
out = sys.stdout
MOD = 1000000007
def main():
n, q = map(int, input().split())
s = input()
d = {}
count_1 = 0
count_0 = 0
for i in range(n):
if s[i] == '1':
count_1 += 1
else:
count_0 += 1
z = (count_1, count_... |
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()
p = [0] * (1 + len(s))
for i, _s in enumerate(s):
if _s == '1':
p[i+1] = p[i] + 1
else:
p[i+1] = p[i]
MOD = 10**9 + 7
#print "prefix", p
out = []
for i in range(q):
l, r = map(int, raw_input().split())
ones = p[r] - p[l-1]
zeros ... |
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 = 100100;
const int mod = 1e9 + 7;
char s[maxn];
int c[maxn], f[maxn];
inline int read() {
int x = 0, t = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = -1, ch = getchar();
while (ch <= '9' && ... |
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 one[100007], zero[100007];
const int mod = 1e9 + 7;
long long FastPow(long long x, long long n, long long mod) {
long long s = 1;
while (n) {
if (n & 1) s = s * x % mod;
x = x * x % mod;
n >>= 1;
}
return s % mod;
}
int main() {
int n, q;
cin >> ... |
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 N = 1e6 + 9;
const long long int mod = 1e9 + 7;
vector<long long int> v[N];
map<long long int, long long int> mpp;
set<long long int> st;
long long int b[N], a[N];
void pre() {
b[0] = 1;
for (int i = 1; i <= N - 6; ++i) b[i] = (b[i - 1] * 2) % mod;
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... | from sys import *
mod=1000000007
n,q=map(int,stdin.readline().split())
s=str(stdin.readline())
arr=[]
count=0
for i in s:
if(i=='1'):
count+=1
arr.append(count)
#q=int(input())
ansarr=[]
for i in range(q):
x,y=map(int,input().split())
if(x==1):
total1=arr[y-1]
else:
total1=arr[y-1]-arr[x-2]
total0=(y-x+1-to... |
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
n,q=map(int,input().split())
s=input()
zero=[]
one=[]
cz=0
c1=0
for i in range(n):
if(s[i]=='0'):
cz+=1
zero.append(cz)
one.append(c1)
else:
c1+=1
zero.append(cz)
one.append(c1)
one=[0]+one
zero=[0]+zero
for i in ran... |
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 codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
static class Input {
private StringTokenizer tokenizer = null;
private BufferedReader ... |
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 Main {
static long mod = 1000000007;
static long getPow(long n, long mod){
if(n == 0) return 1 % mod;
if(n == 1) return 2 % mod;
long res = getPow(n / 2, mod);
if(n % 2 == 0) return (res * res) % mod;
else return (res * res * 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... | from sys import stdout,stdin
n,q=tuple(map(int,stdin.readline().split()))
s=stdin.readline()
mod=1000000007
powers=[1 for i in range(n+1)]
for i in range(1,n+1):
powers[i]=powers[i-1]+powers[i-1]
if powers[i]>=mod:
powers[i]-=mod
cum=[0 for i in range(n+1)]
for i in range(n):
if s[i]=='0':
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 n, q, pref[100010];
char c[100010];
const int MOD = 1e9 + 7;
int fp(int a, int b) {
if (b == 0) return 1;
long long temp = fp(a, b / 2);
temp *= temp;
temp %= MOD;
if (b & 1)
return (temp * a) % MOD;
else
return temp;
}
int main() {
scanf("%d %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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = 1e6 + 10, maxm = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double PI = acos(-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>
using namespace std;
long long l, r, n, q, p[200000], a[200000], k, m, mod = 1e9 + 7;
string s;
int main() {
cin >> n >> q >> s;
for (int i = 0; i < n; i++) {
a[i + 1] += a[i];
if (s[i] == '1') a[i + 1]++;
}
p[0] = 1;
for (int i = 1; i <= 1e5; i++) p[i] = (p[i - 1] * 2) % 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>
const long long md = 1e9 + 7;
const int Inf = 1e9;
const long long Inf64 = 1e18;
const long long MaxN = 2e5 + 10;
const long long MaxM = 11;
const long double eps = 1e-15;
const long long dx[4] = {0, 1, 0, -1};
const long long dy[4] = {1, 0, -1, 0};
const long long ddx[4] = {1, 1, -1, -1};
cons... |
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.StringTokenizer;
public class Main {
static final int mod = (int) (1e9 + 7);
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
... |
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... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.TreeSet;
... |
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 = 10**9+7
n, q = list(map(int, stdin.readline().strip().split()))
s = list(map(int, list(stdin.readline().strip())))
cf = {0:0}
for i in range(1, n+1):
cf[i] = cf[i-1]+s[i-1]
# print(i, cf[i])
for _ in range(q):
l, r = list(map(int, stdin.readline().strip().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 itertools as it
import sys
MOD = 10 ** 9 + 7
n, q = map(int, next(sys.stdin).split())
s = [0] + list(it.accumulate(map(int, next(sys.stdin).strip())))
pow2 = [1]
for _ in range(1, n + 1):
pow2.append((pow2[-1] << 1) % MOD)
ans = []
for _ in range(q):
l, r = map(int, next(sys.stdin).split())
ones =... |
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.*;
public class segment_tree{
static int max = (int)1e5+5;
static int[] a = new int[2*max];
static long mod = (long)1e9+7;
static void build(int n){
for(int i=n-1;i>0;i--)a[i] = a[i<<1]+a[i<<1|1];
}
static int query(int l,int r,int n){
int res = 0;
for(l = l+n,r = r+n;l<r;l>>=1,r>>=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.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
void solve() {
int n=ni(),q=ni();
char s[]=ns().toCharArray();
long pow[]=new long[n+2];
pow[0]=1;
for(int i=1;i<=n+1;i++) pow[i]=mul(pow[i-1],2);
int pref[]=new int[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... | from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
#?############################################################
def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
de... |
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;
string s;
int ar[100005];
int ans[100005];
int anss[100005];
int main() {
int n, q, i, l, r, j, a, b, x;
ans[0] = 1;
for (i = 1; i < 100005; i++) {
ans[i] = (ans[i - 1] * 2) % 1000000007;
}
anss[0] = 1;
for (i = 1; i < 100005; i++) {
anss[i] = (anss[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 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... |
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[])
{
FastReader input=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int T=1;
while(T-->0)
{
int n=input.nextInt();
int q=input.nextInt();... |
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.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class BanhMi {
int MOD = (int) 1e9 + 7;
void solve() {
int n = in.nextInt(), Q = in.nextInt();
ch... |
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... | #!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from __future__ import divisi... |
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.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public stati... |
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 ModPow(long long base, long long exp, long long m) {
long long r = 1;
long long p;
base %= m;
while (exp) {
if (exp & 1) r = (r * base) % m;
exp = exp >> 1;
base = (base * base) % m;
}
return r;
}
int32_t main() {
ios_base::sync_with_stdi... |
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.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
long mod1 = (long) 1e9 + 7;
int mod2 = 998244353;
public void solve() throws Exception {
int n=sc.nextInt();
int q=sc.nextInt();
int one[]=new int[n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.