#include <iostream> #include <vector> using namespace std;   int getRes(vector<char> &arr, int l, int r) {     if(l > r) return 0;     if(l == r && arr[l-1] != '<' && arr[l-1] != '>') return arr[l-1] - '0';     vector<char> tem;     for(int i=l-1; i<r; i++)         tem.push_back(arr[i]);     int flag = 1;     int ind = 0, len = r - l + 1, res = 0;     while(ind >= 0 && ind < len) {         if(tem[ind] == '<') {             if(ind-1 >= 0 && tem[ind-1] == '<' || tem[ind-1] == '>')                 len--, tem.erase(tem.begin() + ind);             ind--, flag = -1;         } else if(tem[ind] == '>') {             if(ind+1 < len && tem[ind+1] == '<' || tem[ind+1] == '>')                 len--, tem.erase(tem.begin() + ind),ind--;             ind++, flag = 1;         } else {             res += tem[ind] - '0';             if(tem[ind] == '0')                 len--, tem.erase(tem.begin() + ind);             else tem[ind]--;             ind += flag;         }         //for(auto &it:tem) cout<< it<< ' '; cout << endl;     }     return res; }   int main() {     int n, m, q, l, r;     cin >> n >> m >> q;     vector<char> arr(n);     for(int i=0; i<n; i++)         cin >> arr[i];     for(int i=0; i<q; i++) {         cin >> l >> r;         int res = getRes(arr, l, r);         cout << res << endl;     }     return 0; }
点赞 1

相关推荐

CARLJOSEPH...:宝宝你戾气太大了
点赞 评论 收藏
分享
认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务