F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Neko and sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 94    Accepted Submission(s): 24


Problem Description
One day, Inu asked Neko a question:
Give you a sequence with $n$ elements. The index for the first element is $0$, the last is $n-1$.
They are arranged in rings. $0$ and $n-1$ are next to each other.
The $i$-th element has a character $s[i]$ which is '(' or ')'.
Let $f(i, d)$ means the last place to arrive by starting with $i$ and taking $d$ steps.
If you are in $i$-th element now and $s[i] = $'(', you will arrive $(i-k+n)\%n$-th element in next step, or you will arrive $(i+k)\%n$-th element.
And there are $q$ questions.Each question has three integers $l, r, d$. You have to calculate $\sum_{i = l}^{r} f(i,d)$
 

Input
The first line contains three integers $n, q, k(1 \leq n, q \leq 10^{5}, 1 \leq k < n)$ .
The second line contains a sequence, the $i$-th element means $s[i]$ .
The next $q$ line, each line contains three integers $l,r,d(0 \leq l \leq r < n, 1 \leq d \leq 10^{9})$ .
 

Output
For each question output the sum in one line.
 

Sample Input
6 5 1 ())()( 0 1 3 1 3 2 1 4 3 2 5 6 0 3 4
 

Sample Output
7 8 12 14 12
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 11:56:04, Gzip enabled