Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
A simplified arithmetic expression (SAE) is an arithmetic expression defined by the following grammar: ::= | + | * | ( ) ::= | ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 In other words it's a correct arithmetic expression that is allowed to contain brackets, numbers (possibly with leading zeros), multiplications and additions. For example expressions " (0+01) ", " 0 " and " 1*(0) " are simplified arithmetic expressions, but expressions " 2-1 ", " +1 " and " 1+2) " are not. Given a string s 1 s 2 ... s | s | that represents a SAE; s i denotes the i -th character of the string which can be either a digit (' 0 '-' 9 '), a plus sign (' + '), a multiplication sign (' * '), an opening round bracket ' ( ' or a closing round bracket ' ) '. A part s l s l + 1 ... s r of this string is called a sub-expression if and only if it is a SAE. You task is to answer m queries, each of which is a pair of integers l i , r i (1 ≤ l i ≤ r i ≤ | s |) . For each query determine whether the corresponding part of the given string is a sub-expression and in case it's a sub-expression calculate its value modulo 1000000007 (10 9 + 7) . The values should be calculated using standard operator priorities. The first line of the input contains non-empty string s (1 ≤ | s | ≤ 4·10 5 ) which represents a correct SAE. Each character of the string can be one of the following characters: ' * ', ' + ', ' ( ', ' ) ' or a digit (' 0 '-' 9 '). The expression might contain extra-huge numbers. The second line contains an integer m (1 ≤ m ≤ 4·10 5 ) which is the number of queries. Each of the next m lines contains two space-separated integers l i , r i (1 ≤ l i ≤ r i ≤ | s |) — the i -th query. The i -th number of output should be the answer for the i -th query. If the i -th query corresponds to a valid sub-expression output the value of the sub-expression modulo 1000000007 (10 9 + 7) . Otherwise output -1 as an answer for the query. Print numbers on separate lines. |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
22571381 |
baxbaxa |
L |
Nov. 28, 2016, 10:53 a.m. |
OK |
GNU C++ |
TESTS |
69 |
920 |
145715200 |
|
3300 |
|
26373476 |
Iliaplt |
L |
April 15, 2017, 7:33 a.m. |
OK |
GNU C++ |
TESTS |
69 |
967 |
55808000 |
|
3300 |
|
21765889 |
lucyanna2018 |
L |
Oct. 25, 2016, 7:49 a.m. |
OK |
GNU C++ |
TESTS |
69 |
1014 |
53657600 |
|
3300 |
|
21951203 |
yancouto |
L |
Oct. 31, 2016, 9:21 p.m. |
OK |
GNU C++11 |
TESTS |
69 |
483 |
164454400 |
|
3300 |
|
40983301 |
ReaLNero1 |
L |
July 30, 2018, 6:48 p.m. |
OK |
GNU C++11 |
TESTS |
69 |
498 |
164454400 |
|
3300 |
|
23921315 |
mggamer |
L |
Jan. 18, 2017, 12:14 p.m. |
OK |
GNU C++11 |
TESTS |
69 |
514 |
166604800 |
|
3300 |
|
49100348 |
ko_osaga .o. alex9801 |
L |
Jan. 28, 2019, 11:08 a.m. |
OK |
GNU C++11 |
TESTS |
69 |
608 |
70553600 |
|
3300 |
|
21908747 |
NiroBC |
L |
Oct. 31, 2016, 10:27 a.m. |
OK |
GNU C++11 |
TESTS |
69 |
623 |
72396800 |
|
3300 |
|
21903014 |
SimB4 |
L |
Oct. 31, 2016, 4:01 a.m. |
OK |
GNU C++11 |
TESTS |
69 |
654 |
256819200 |
|
3300 |
|
22223014 |
krijgertje |
L |
Nov. 15, 2016, 1:20 p.m. |
OK |
GNU C++11 |
TESTS |
69 |
764 |
27648000 |
|
3300 |
|
22078873 |
yarek |
L |
Nov. 6, 2016, 4:28 p.m. |
OK |
GNU C++11 |
TESTS |
69 |
857 |
69017600 |
|
3300 |
|
23357950 |
Ali.Pi |
L |
Dec. 27, 2016, 11:25 a.m. |
OK |
GNU C++11 |
TESTS |
69 |
936 |
71168000 |
|
3300 |
|
21710741 |
anta |
L |
Oct. 23, 2016, 11:53 a.m. |
OK |
GNU C++11 |
TESTS |
69 |
951 |
135065600 |
|
3300 |
|
21819584 |
izban enot110 Belonogov |
L |
Oct. 27, 2016, 11:20 a.m. |
OK |
GNU C++14 |
TESTS |
69 |
577 |
139161600 |
|
3300 |
|
22064718 |
mnbvmar |
L |
Nov. 5, 2016, 8:45 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
795 |
95334400 |
|
3300 |
|
21713522 |
unused |
L |
Oct. 23, 2016, 1:21 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
1091 |
74854400 |
|
3300 |
|
22060639 |
Errichto mareksom Radewoosh |
L |
Nov. 5, 2016, 4:36 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
1216 |
283750400 |
|
3300 |
|
21719738 |
viesis |
L |
Oct. 23, 2016, 6:42 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
1263 |
181760000 |
|
3300 |
|
21715184 |
1234 |
L |
Oct. 23, 2016, 2:43 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
1263 |
181760000 |
|
3300 |
|
21714815 |
ashwanidv100 |
L |
Oct. 23, 2016, 2:22 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
1263 |
181760000 |
|
3300 |
|
21714033 |
ashwanidv100 |
L |
Oct. 23, 2016, 1:43 p.m. |
OK |
GNU C++14 |
TESTS |
69 |
1263 |
181760000 |
|
3300 |
|
69707488 |
gongsuidashen |
L |
Jan. 29, 2020, 5:27 a.m. |
OK |
GNU C++17 |
TESTS |
69 |
639 |
164659200 |
|
3300 |
|
48503940 |
Qingyu |
L |
Jan. 17, 2019, 4:39 p.m. |
OK |
GNU C++17 |
TESTS |
69 |
780 |
131993600 |
|
3300 |
|
62215709 |
snowwm |
L |
Oct. 9, 2019, 3:54 p.m. |
OK |
GNU C++17 |
TESTS |
69 |
2526 |
446566400 |
|
3300 |
|
21718319 |
noxwell |
L |
Oct. 23, 2016, 5:35 p.m. |
OK |
MS C++ |
TESTS |
69 |
3946 |
453427200 |
|
3300 |
remove filters
Back to search problems