ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215023 | #2410. 图案 | wujiachen | 0 | 0ms | 0kb | C++ | 1.1kb | 2024-11-25 20:04:56 | 2024-11-25 23:07:57 |
answer
#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int ll[1000005],rr[1000005];
bool ll1[1000005],rr1[1000005];
stack<int> st;
int main(){
string s;
cin>>s;
int cnt=0;
for(int i=0;i<s.size();i++){
if(s[i]=='('){
cnt++;
st.push(i+1);
}
else if(cnt){
cnt--;
ll1[st.top()]=1;
st.pop();
ll[i+1]+=2;
}
ll[i+1]+=ll[i];
}
while(st.size()){
st.pop();
}
cnt=0;
for(int i=s.size()-1;i>=0;i--){
if(s[i]==')'){
cnt++;
st.push(i+1);
}
else if(cnt){
cnt--;
rr1[st.top()]=1;
st.pop();
rr[i+1]+=2;
}
rr[i+1]+=rr[i+2];
}
int n;
cin>>n;
for(int i=1;i<=n;i++){
int l,r,ans=0;
scanf("%d%d",&l,&r);
ans=ll[s.size()]-ll[l-1]-rr[r+1];
if(l!=1&&ll1[l-1]){
if(s[l-2]=='(')ans-=2;
}
if(r!=s.size()&&rr1[r+1]){
if(s[r]==')')ans-=2;
}
cout<<ans<<endl;
}
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
100 2 xxyxxyyxxyxxyypxxyxxyyxxyxxyypxxyxxyyxxyxxyypwxxyxxyyxxyxxyypxxyxxyyxxyxxyypxxyxxyyxxyxxyypwex...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #14:
score: 0
Runtime Error
input:
100 2 xxyxxyyxxyxxyypxxyxxyyxxyxxyypxxyxxyyxxyxxyypwxxyxxyyxxyxxyypxxyxxyyxxyxxyypxxyxxyyxxyxxyypwex...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #51:
score: 0
Runtime Error
input:
1000000 23 cicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicic...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #57:
score: 0
Runtime Error
input:
100 2 xxyxxyyxxyxxyypxxyxxyyxxyxxyypxxyxxyyxxyxxyypwxxyxxyyxxyxxyypxxyxxyyxxyxxyypxxyxxyyxxyxxyypwex...