题目大意:
给你一个字符串,要你找到一些子区间使得s[l,r]的在十进制下的值 mod 2019 = 0,现在问你有多少这样的子区间。
思路:
如果s[L,R] % p = 0,那么必然有 s[L,R] * 10 ^ k % p = 0.
如果S[L,N] % p = S[R,N] % p,那么就会有S[L,N] % p - S[R,N] % p = 0 mod p。
如果我们需要找到同余下相同的数。并且是s[L,N]找s[R,N],其中R >= L,所以我们可以从后面往前面求。
代码:

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
void solved(){
	string s;cin>>s;
	int ans = 0;
	map<int,int>mp;
	int cnt = 0;
	mp[0] = 1;
	int p = 1;
	for(int i = s.size() - 1; i >= 0; i--){
		ans = (ans + ll(s[i] - '0') * p)%2019;
		cnt += mp[ans]++;
		p = p * 10 % 2019;
	}
	cout<<cnt<<endl;
}
int main(){
	solved();
	return 0;
}