https://ac.nowcoder.com/acm/contest/888#question
B
Attendance problem, the code can be really short.
The meaning of problems: a number n, for each successive sub-sequences of different numbers of request number and interval.
Practice: a start point of each enumeration of the right section i, determining each number in the interval left point to right point contributions i i ~ 1 within this range, then the answer accumulation, and overtime.
After expect, each range change only becomes a digital changes only contribute a digital, open the contribution a record sum of all the numbers just fine.
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; #define ll long long int maxx[maxn]; int main() { int n; scanf("%d",&n); ll ans=0; ll sum=0; int t; for(int i=1; i<=n; i++) { scanf("%d",&t); sum=sum-maxx[t]+i; maxx[t]=i; ans=ans+sum; } printf("%lld",ans); }
G
Sign problem
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; char s[maxn]; int main() { scanf("%s",s+1); int len=strlen(s+1); int ans=0; stack<char> st; for(int i=1; i<=len; i++) { st.push(s[i]); if(st.size()>=3) { char c1=st.top();st.pop(); char c2=st.top();st.pop(); char c3=st.top();st.pop(); if(c1==c2&&c2==c3) ans++; else { st.push(c3);st.push(c2);st.push(c1); } } } printf("%d",ans); }