Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=input()
a=map(int,raw_input().split())
for i in range(1,n):
a[i]+=a[i-1]
l={}
j=1
count=1
while j<=a[-1]:
l[j]=count
if j+1>a[count-1]:
count+=1
j+=1
#print l
q=input()
aq=map(int,raw_input().split())
for i in range(q):
print l[aq[i]] | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
public class game {
public static int search(int[] arr,int start,int end, int val) {
int mid = (end + start)/2;
if(start == end - 1) {
if(val <= arr[start]) {
return start+1;
}
else
return end + 1;
}
if(val > arr[mid]) {
return search(arr, mid , end, val);
}
else if(... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
import os
def search(Max,new,num):
if new[0]>num:
return 1
Min =0
Mid = int((Max+Min)/2)
while Min<=Max:
if new[Mid]==num:
return Mid+1
break
elif new[Min]==num:
return Min+1
break
elif new[Mid]<num and new[Mid+1]>num:
return Mid+2
break
elif new[Mid]<num:
Min=Mid+1
else... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
lis = [int(i) for i in input().split()]
m = int(input())
lis1 = [int(i) for i in input().split()]
c = 1
check = []
for i in lis:
check.extend([c]*i)
c += 1
for i in lis1:
print(check[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
arr = list(map(int, input().split()))
m = int(input())
jw = list(map(int, input().split()))
res = [0] * m
from itertools import accumulate
acc = list(accumulate(arr))
sorted_indices = sorted(range(m), key=lambda i: jw[i])
acc_indices = list(range(n))
i = j = 0
while i < m:
val = jw[sorte... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
s = 0
arr = [0 for i in range(10**6+10)]
x = [int(i) for i in raw_input().split()]
for i in xrange(n):
for j in range(s+1,s+x[i]+1):
arr[j] = i+1
s += x[i]
m = int(raw_input())
x = [int(i) for i in raw_input().split()]
for i in xrange(m):
print arr[x[i]]
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, z = 1;
cin >> n;
int a[n];
int tot[n];
cin >> a[0];
tot[0] = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
tot[i] = tot[i - 1] + a[i];
}
int m;
cin >> m;
int q[m];
for (int i = 0; i < m; i++) {
cin >> q[i];
}
fo... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(raw_input())
a= map(int,raw_input().split())
m=int(raw_input())
q= map(int,raw_input().split())
accu=0
for i in xrange(n):
accu+=a[i]
a[i]=accu
#print a
for qi in q:
print bisect.bisect_left(a,qi)+1
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
list1 = list(map(int,input().split()))
m = int(input())
list2 = list(map(int,input().split()))
w = [0]*100002
s = 1
for i in range(n):
w[s:s+list1[i]] = [i+1]*list1[i]
s += list1[i]
for k in range(m):
print(w[list2[k]])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary_search(q,a):
l=0
h=len(a)
while l!=h:
mid=(l+h)//2
if a[mid]<=q:
l=mid+1
else:
h=mid
return l
n=int(input())
a=list(map(int,input().split()))
m=int(input())
Ql=list(map(int,input().split()))
for i in range(1,len(a)):
a[i]+=a[i-1]
for i in ran... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int dp[] = new int[1000001];
i... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def BinSearch(L , N, start, end) :
mid = (start + end)//2
if end - start <= 1 :
if L[start] >= N :
return start
else :
return end
elif L[mid] >= N and L[mid - 1] < N :
return mid
elif L[mid] > N :
return BinSearch(L,N ,start, mid - 1)
else :... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | N = int(raw_input())
entradas = map(int, raw_input().split())
juicys = int(raw_input())
m = map(int, raw_input().split())
total = sum(entradas)
mapa = {}
pilha = 1
n = 0
fim = entradas[n]
for i in range(total):
numero = i + 1
if (numero <= fim):
mapa[numero] = pilha
else:
pilha += 1
n += 1
fim = fim + entr... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
q = [int(x) for x in input().split()]
worm = []
for x in range(n):
for y in range(a[x]):
worm.append(x+1)
for x in range(m):
print(worm[q[x]-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int f[100000];
int main() {
int n;
cin >> n;
int a;
cin >> a;
f[0] = a;
for (int i = 1; i < n; i++) {
int a;
cin >> a;
f[i] = a + f[i - 1];
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
cout << lower_bound(f, f... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, a[100009], sum[100009];
int bin(int L, int R, int x) {
while (L < R) {
int M = (L + R) >> 1;
if (sum[M] >= x)
R = M;
else
L = M + 1;
}
return R;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = input()
a = map(int,raw_input().split())
m = input()
j = map(int,raw_input().split())
for i in range(1,n):
a[i] = a[i]+a[i-1]
for i in j:
print bisect.bisect_left(a,i,0,n) + 1 | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
arr= list(map(int,input().split()))
k = int(input())
arr_j = list(map(int,input().split()))
arr_cum = [0 for i in range(n)]
for i in range(n):
arr_cum[i] = arr[i] + arr_cum[i-1]
def binarSearch(arr,m):
l = 0
r = n-1
while l<=r:
mid = l + (r-l)//2
if arr[mid] >= m:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
na=list(map(int,input().split()))
q=int(input())
b=list(map(int,input().split()))
a=[]
sm=0
for i in range(len(na)):
sm=sm+na[i]
a.append(sm)
for i in b:
ans=bisect.bisect_left(a,i)
print(ans+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | /*
* 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.util.Scanner;
/**
*
* @author Darkhan
*/
public class Main {
public static void main(String[] args) {
Sca... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.math.BigInteger;
public class b {
public static void main(String[] arg)
{
new b();
}
public b()
{
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int[] arr = new int[size];
arr[0] = in.nextInt();
for(int i = 1; i < size; i++) arr[i] = arr[i-1] + in.nextInt(... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def BinarySearch(alist,item):
low=0
high=len(alist)
while low<high:
mid=(high+low)//2
if alist[mid]<item:
low=mid+1
else:
high=mid
return low
input()
poles = list(map(int,input().split()))
input()
juicy = list(map(int,input().split()))
sm=0
worms=[]
for... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
nums=[0]+[int(x) for x in input().split()]
m=int(input())
labs=[int(x) for x in input().split()]
index=[0]*(n+1)
t=1
for i in range(1,len(nums)):
index[t:t+nums[i]]=[i]*nums[i]
t+=nums[i]
for i in labs:
print(index[i]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
my_list = []
for i in range(n):
my_list += [i+1] * a[i]
for i in q:
print(my_list[i-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class B extends Thread {
static class FastReader {
BufferedReader br;
StringTokenize... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 3;
const int N = 4e5 + 10;
int a[N];
int main() {
a[0] = 0;
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1];
int m;
cin >> m;
while (m--) {
int q;
cin >> q;
int ans = -1;
int l = 1;
int r = ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #!/usr/bin/python
from collections import deque
def ir():
return int(raw_input())
def ia():
line = raw_input()
line = line.split()
return map(int, line)
n = ir()
a = ia()
m = ir()
q = ia()
s = 0
c = [0]
for e in a:
s = s + e
c.append(s)
# a, b, c
# [1, a], [a+1, a+b], [a+b+1, a+b+c]
# 0 ... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
int w[1000000];
int main() {
int n, pre = 0, cur, cur_worm, m, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &cur);
for (j = pre + 1; j <= pre + cur; j++) w[j] = i + 1;
pre += cur;
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d", &cur_worm);
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
import java.lang.*;
public class code2
{
public static void main(String[] args)
{
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(System.out);
//Code starts..
int n = in.nextInt();
int[] a = new int[n];
long[] p... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def Worm(l,p):
tmp=0
d=p[:]
ranges=[]
result={}
for i in range(len(l)):
ranges.append((tmp+1,int(l[i])+tmp))
tmp=int(l[i])+tmp
p.sort()
tmp=0
for x in p:
while(1):
if ranges[tmp][0]<=int(x) and ranges[tmp][1]>=int(x):
result[x]=tmp+1
break
else:
tmp+=1
for x in d:
print(result[x])
inp... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #------------------------------what is this I don't know....just makes my mess faster--------------------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer =... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # 474B - Worms
# http://codeforces.com/problemset/problem/474/B
n = int(input())
a = [int(x) for x in input().split()]
lookup = []
group_no = 0
for x in a:
group_no += 1
for i in range(x):
lookup.append(group_no)
m = int(input())
b = [int(x) for x in input().split()]
for x in b:
print(lookup[x - 1... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | ########################################
# SUBTRACTIONS #
########################################
# for _ in range(int(input())):
# a, b = map(int, input().split())
# c = 0
# while(min(a, b) != 0):
# ma = max(a, b)
# mi = min(a, b)
# a = mi
# b = m... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class worms
{
publ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
n = int(sys.stdin.readline())
ind = sys.stdin.readline().strip().split(' ')
m = int(sys.stdin.readline())
q = sys.stdin.readline().strip().split(' ')
ar = []
for i in range(0, n):
for j in range(0, int(ind[i])):
ar.append(i)
for i in range(0, m):
print(ar[int(q[i]) - 1] + 1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) cin >> v[i];
;
for (long long i = 1; i < n; i++) {
v[i] += v[i - 1];
}
int m;
cin >> m;
long long a;
int ans;
while (m--) {
cin >> a;
ans = lower_bo... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
a = [int(x) for x in raw_input().strip().split()]
m = int(raw_input())
b = [int(x) for x in raw_input().strip().split()]
r = []
for i in range(n):
s = [i]*a[i]
r.extend(s)
for x in b:
print r[x-1]+1
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int x[1000003], p = 1, t, q, n, m;
int main() {
cin >> n;
for (q = 1; q <= n; q++) {
cin >> t;
while (t--) x[p] = q, p++;
}
cin >> m;
while (m--) cin >> t, cout << x[t] << endl;
}
| CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.*;
public class worms {
public static void main(String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
int n=Integer.parseInt(br.readLine());
long[] a... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
s=list(map(int,input().split()))
n1=int(input())
s1=list(map(int,input().split()))
w=[]
i=-1
d=n-1
r=0
while i!=d:
i+=1
for j in range(s[i]):
r+=1
w.append(r)
ans=[]
for i in range(n1):
l,r=-1,n
while (l+1<r):
md=(l+r)//2
if s1[i]<=w[md]:
r=md
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def bs(array, i):
low = 0
high = len(array)-1
while(low<high):
mid = (low+high)//2
if array[mid]>=i:
high = mid
else:
low = mid+1
return low
n = int(input())
array = [int (i) for i in input().split()]
s = 0
for i in range(n):
s += array[i]
array[i] = s
t = int(input())
tc = [int(i) for i in input()... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
def solve():
n=int(input())
a=list(map(int,input().split()))
p=[0]*len(a)
p[0]=a[0]
for i in range(1, len(a)):
p[i] = p[i-1] + a[i]
m=int(input())
l=list(map(int,input().split()))
for i in l:
x = bisect.bisect_left(p,i)
print(x+1)
solve()
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
piles = [int(g) for g in raw_input().split()]
m = int(raw_input())
worms = [int(h) for h in raw_input().split()]
limits = []
so_far = 0
answers = []
for i in range(n):
so_far += piles[i]
limits.append(so_far)
for j in range(piles[i]):
answers.append(i+1)
for i in range(m):
print answers[wo... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binsearch(nums, target):
left = 0
right = len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
right = mid - 1
elif nums[mid] < target:
left = mid + 1
return left
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
x=list(map(int,input().split()))
t=int(input())
y=list(map(int,input().split()))
ans=[]
for i in range(len(x)):
ans.extend([i+1 for j in range(x[i])])
for i in y:
print(ans[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Worms {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamRea... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n, a = input(), map(int, raw_input().split(" "))
m, b = input(), map(int, raw_input().split(" "))
worms = [0]
i = 1
for amt in a:
worms += [i] * amt
i += 1
for worm in b:
print worms[worm]
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binarySearch(alvo, soma, pilhas):
inicio = 0
fim = pilhas - 1
while True:
if inicio > fim:
break
meio = (fim + inicio) / 2
if soma[meio] < alvo:
inicio = meio + 1
elif soma[meio] > alvo:
fim = meio - 1
else:
inicio = meio
break
return inicio
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
n1=int(input())
e=list(map(int,input().split()))
b1=0
c=[]
d={}
for i in range(len(a)):
b1+=a[i]
c.append(b1)
b=sorted(e)
j=0
for i in range(len(b)):
if b[i] not in d:
for k in range(j,len(c)):
if c[k]>=b[i]:
d[b[i]]... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def bsearch(arr, el):
start = 0
end = len(arr)-1
while(start<=end):
mid = (start+end)//2
if(arr[mid]>el):
end = mid-1
elif(arr[mid]<el):
start = mid+1
else:
return mid+1
if(arr[start] > el):
return start+1
else:
ret... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect
def accumulate(ls):
total = 0
for i in ls:
total += i
yield total + 1
n_piles = int(raw_input())
piles = map(int, raw_input().split(' '))
n_juicy = int(raw_input())
juicy = map(int, raw_input().split(' '))
indices = list(accumulate(piles))
for i in juicy:
print bis... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def main():
heapsC = int(input())
heaps = list(map(int, input().split(" ")))
wormsC = int(input())
worms = list(map(int, input().split(" ")))
prev = heaps[0]
for i in range(1, heapsC):
heaps[i] = heaps[i] + prev
prev = heaps[i]
for value in worms:
left = 0
r... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
l=[int(s) for s in input().split()]
m=int(input())
l2=[int(s) for s in input().split()]
for i in range(1,n):
l[i]+=l[i-1]
for i in range(m):
k=bisect.bisect_left(l,l2[i])
print(k+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author mthai
*/
public class Main ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
int arr[n];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
if (i > 0) arr[i] += arr[i - 1];
}
int q;
cin >> q;
int x, l, r, mid;
while (q--) {
cin >> x;
l = 0, r = n - 1;
while (l < r) {
mid = l +... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
q = [int(i) for i in input().split()]
b = []
for i in range(n):
for j in range(a[i]):
b.append(i+1)
for i in q: print(b[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, x, temp;
vector<long long> sum;
vector<long long> search;
vector<long long> ans;
long long cur = 0;
sum.push_back(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
temp = x + sum[sum.size() - 1];
sum.push_back(tem... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
a = map(int, raw_input().split(' '))
m = int(raw_input())
q = map(int, raw_input().split(' '))
dic = {}
index = 0
s = 1
for i in range(n):
for j in range(s, s + a[i] + 1):
dic[j] = index
s += a[i]
index += 1
for i in range(m):
print dic[q[i]] + 1 | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, piles[100000], q;
cin >> n;
cin >> q;
piles[0] = q;
for (int i = int(1); i < int(n); i++) {
cin >> q;
piles[i] = piles[i - 1] + q;
}
cin >> m;
for (int i = int(0); i < int(m); i++) {
cin >> q;
int ans = upper_bound(pile... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
lsn=list(map(int,input().split()))
m=int(input())
lsm=list(map(int,input().split()))
lst=[]
c=0
for i in lsn:
c=c+i
lst.append(c)
#print(lst)
for j in lsm:
s=0
e=len(lst)-1
#print(j)
while 1:
if e-s==1:
print(e+1)
break
mid=int((s+e)/2)
#print('start:'+str(s))
#print('mid:'+str(mid))
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | na = int(input())
a = list(map(int,input().split()))
qa = int(input())
q = list(map(int,input().split()))
beg = 0
end = 0
ans = []
for i in range(na) :
for _ in range(a[i]):
ans.append(i+1)
for x in q :
print(ans[x-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #alphabet = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
a = list(map(int, input().split()))
last = 0
for i in range(n):
a[i] += last
last = a[i]
m = int(input())
q = map(int, input().split())
for ch in q:
l = 0
r = n - 1
middle = (l+r)//2
while l < r:
if ch > a[middle]:
l =... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | input()
a = []
r = 1
for k in input().split():
a += [r] * int(k)
r += 1
input()
for k in input().split():
print(a[int(k) - 1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(input())
a = list()
arr = raw_input().split(' ')
a = [int(num) for num in arr]
for i in range(1,n):
a[i] = a[i-1] + a[i]
m = int(input())
q = list()
arr = raw_input().split(' ')
q = [int(num) for num in arr]
for i in range(0,m):
i = bisect.bisect_left(a,q[i])
print(i+1) | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
piles = [int(i) for i in input().split()]
worms = []
for i in range(n):
worms.extend([i+1] * piles[i])
m = int(input())
qs = [int(i) for i in input().split()]
for q in qs:
print(worms[q-1]) | PYTHON3 |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
static class Reader
{
BufferedReader r;... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | x1,y1 = [int(i) for i in input().split()]
x2,y2 = [int(i) for i in input().split()]
n = int(input())
m = 0
for i in range(n):
x,y,c = [int(g) for g in input().split()]
if(x1*x+y1*y+c>0):
l = 1
else:
l = -1
if(l==-1)and(x2*x+y2*y+c>0):
m+=1
elif(l==1)and(x2*x+y2*y+c<0):
... | PYTHON3 |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
inline bool Ok(long double a, long double b, long double c) {}
int main() {
long double x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
int n, ret = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
long double a, b, c;
cin >> a >> b >> c;
long double Y1 = (-a ... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
const int maxn = 500;
int ax, ay, bx, by;
int n;
int a[maxn], b[maxn], c[maxn];
int side[maxn];
int main() {
scanf("%d%d", &ax, &ay);
scanf("%d%d", &bx, &by);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
if (1LL * a[i] * ax + 1LL * b[i] * ... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
} w[2];
int32_t main() {
long long ans = 0;
for (long long i = 0; i < 2; i++) {
scanf("%lld%lld", &w[i].x, &w[i].y);
}
long long n;
scanf("%lld", &n);
for (long long i = 0; i < n; i++) {
long long a, b, c;
scanf("%lld... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c;
long long x1, y1, x2, y2;
int n, cnt = 0;
cin >> x1 >> y1 >> x2 >> y2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
long long t1 = a * x1 + b * y1 + c;
long long t2 = a * x2 + b * y2 + c;
if ((t1 < 0... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
/**
*... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
long long a[305], b[305], c[305];
int main() {
int n;
pair<long long, long long> p[2];
long long r[2];
for (int i = 0; i < 2; i++) scanf("%lld%lld", &p[i].first, &p[i].second);
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
scanf("%lld%lld%lld... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double pi = acos(-1.0);
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
struct point_i {
int x, y;
point_i() { x = y = 0; };
point_i(int x_, int y_) : x(x_), y(y_) {}
};
struct line {
double a, b, c;
};
... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
n = int(input())
count = 0
for _ in range(n):
a,b,c = map(int,input().split())
p = x1*a+y1*b+c
q = x2*a+y2*b+c
if (p*q<0):
count += 1
print(count)
| PYTHON3 |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.io.*;
import java.util.*;
public class tr1 {
static PrintWriter out;
static StringBuilder sb;
static int inf = (int) 1e9;
static long mod = 998244353;
//static int[]ans;
static HashSet<Integer>[]ad;
static boolean []vis;
public static void main(String[] args) throws IOException {
Scanner sc = new... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | def ReadArray():
return map(int, raw_input().split())
x, y = ReadArray()
x2, y2 = ReadArray()
n = int(raw_input())
lines = [ReadArray() for _ in xrange(n)]
ans = 0
m = bb = xx = 0
if x != x2:
m = (y - y2) * 1.0 / (x - x2)
bb = y - m*x
for a, b, c in lines:
if x == x2: # vertical line
if b == 0:
con... | PYTHON |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x1, y1, x2, y2, cs = 0, a, b, c, v1, v2;
scanf("%lld %lld", &x1, &y1);
scanf("%lld %lld", &x2, &y2);
scanf("%lld", &n);
while (n--) {
scanf("%lld %lld %lld", &a, &b, &c);
v1 = x1 * a + y1 * b + c;
v2 = x2 * a + y2 * b + c;
... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8, oo = 1e18, PI = acos(-1.0);
struct point {
double x, y;
point(double _x, double _y) : x(_x), y(_y) {}
};
struct line {
double a, b, c;
line(double _a, double _b, double _c) : a(_a), b(_b), c(_c) {}
line(point u, point v) {
a = u.y - v.... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.util.HashMap;
import java.util.Scanner;
/**
* Created by user on 07.02.2015.
*/
public class Main {
private static class point{
int x, y;
private point(int x, int y) {
this.x = x;
this.y = y;
}
}
private static class interval {
point p1, p2;
private interval (point p... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
struct rec {
double a, b, c;
};
rec d[100000];
int n;
double x11, y11, x2, y2;
double dis(double u, double v, double x, double y) {
return (u - x) * (u - x) + (v - y) * (v - y);
}
void process() {
cin >> x11 >> y11 >> x2 >> y2;
cin >> n;
for (int i = 1; i <= n; i+... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
struct point {
long double x, y;
point() {}
point(long double _x, long double _y) : x(_x), y(_y) {}
};
point p1, p2, p3, p4;
int a, b, c;
int n, ans;
long double cross(point a, point b) { return a.x * b.y - a.y * b.x; }
point tovec(point a, point b) { return point(b.x - a.x, b.y - a.y); }... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int x, y, xx, yy, dax[500], day[500], dac[500], i, j, k, l, n, q1,
q2, a;
while (cin >> x >> y >> xx >> yy >> n) {
for (i = 0; i < n; i++) {
cin >> dax[i] >> day[i] >> dac[i];
}
a = 0;
for (i = 0; i < n; i++) {
q1... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
bool res(long long a, long long b, long long c, long long x, long long y) {
return ((long long)a * x + b * y + c) > 0;
}
bool mismatch(int a, int b, int c, int x1, int x2, int y1, int y2) {
return res(a, b, c, x1, y1) ^ res(a, b, c, x2, y2);
}
int main() {
int t = 1;
... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 10000000;
int sgn(long long x, long long y) {
if (!x || !y) return 0;
int a, b;
if (x < 0)
a = -1;
else
a = 1;
if (y < 0)
b = -1;
else
b = 1;
return a * b;
}
int main() {
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.util.*;
public class CFCC135{
public static void main(String args[]){
Scanner ob=new Scanner(System.in);
//System.out.println("SAKJJ");
long x1=ob.nextInt(),y1=ob.nextInt();
long x2=ob.nextInt(),y2=ob.nextInt();
long n=ob.nextInt();
long sum=0;
for... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int st(int x, int pos) { return x = x | (1 << pos); }
int Reset(int x, int pos) { return x = x & ~(1 << pos); }
long long x, y, xx, yy;
long long fn(long long a, long long b, long long c) {
return ((a * x + b * y + c) / abs((a * x + b * y + c))) *
((a * xx + b * ... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.util.Scanner;
/**
*
* @author hunter
*/
public class CrazyTown {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
long x1=in.nextInt() , y1= in.nextInt();
long x2=in.nextInt() , y2= in.... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long x1, x2, y1, y2, a, b, c, n, ans = 0;
cin >> x1 >> y1 >> x2 >> y2;
cin >> n;
while (n--) {
cin >> a >> b >> c;
long long z1 = a * x1 + b * y1 + c;
long long z2 = a * x2 + b * y2 + c;
if ((z1 > 0 && z2 < 0) || (z1 < 0 && z2 > 0))... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import org.xml.sax.InputSource;
public class CrazyTown {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(Sys... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
inline int nxt() {
int n;
scanf("%d", &n);
return n;
}
template <class T>
T sqr(T a) {
return a * a;
}
inline bool check(long long a, long long b, long long c, pair<int, int> first,
pair<int, int> second) {
if (a * first.first + b * first.second ... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int n;
cin >> n;
int count = 0;
while (n--) {
long long int ax, by, c;
cin >> ax >> by >> c;
if (((ax * x1 + by * y1 + c) > 0 && (ax * x2 + by * y2 + c) < 0) ||
((ax * x1... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
namespace chtholly {
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) f ^= c == '-';
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
return f ? x : -x;
}
template <typename mitsuha>
inline bool read(mitsuha &x) {
x =... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000,1000000000")
using namespace std;
struct point {
long double x;
long double y;
};
int main() {
point p1, p2;
cin >> p1.x >> p1.y >> p2.x >> p2.y;
int n;
int k = 0;
cin >> n;
for (int i = 0; i < n; i++) {
long double a, b, c;
cin... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
double x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
int n, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
double a, b, c;
cin >> a >> b >> c;
if ((a * x1 + b * y1 + c < 0 && a * x2 + b * y2 + c > 0) ||
(a * x1 + b * y1 + c > 0 &&... | CPP |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | from sys import stdin
def point_in_line(a, b, c, p):
return a * p[0] + b * p[1] + c
rints = lambda: [int(x) for x in stdin.readline().split()]
p1, p2 = [rints() for _ in range(2)]
n = int(input())
lines, ans = [rints() for _ in range(n)], 0
for a, b, c in lines:
s1, s2 = point_in_line(a, b, c, p1), point_i... | PYTHON |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Crazy_Town {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(Syst... | JAVA |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | read = lambda: map(int, input().split())
dist = lambda P, a, b, c: a * P[0] + b * P[1] + c
P1, P2 = tuple(read()), tuple(read())
n = int(input())
ans = 0
for i in range(n):
a, b, c = read()
d1 = dist(P1, a, b, c)
d2 = dist(P2, a, b, c)
ans += d1 * d2 < 0
print(ans)
| PYTHON3 |
498_A. Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | 2 | 7 | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class CrazyTown {
static double eps = 1e-10;
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] l = bf.readLine().split(" ");
long x1 = Integer.pars... | JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.