Advertisement
bibaboba12345

Untitled

Dec 10th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #pragma GCC optimize("Ofast,unroll-loops")
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <cmath>
  7. #include <iomanip>
  8. #include <string>
  9. #include <set>
  10. using namespace std;
  11.  
  12. const int N = 5e5 + 7,MOD = 1e4;
  13.  
  14. int a[N], n, q, l, r;
  15. long long ans = 0;
  16.  
  17.  
  18. int main() {
  19. /*freopen("z-function.in", "r", stdin);
  20. freopen("z-function.out", "w", stdout);*/
  21. ios::sync_with_stdio(false);
  22. cin.tie(0);
  23. cin >> n >> q;
  24. for (int i = 0; i < n; i++) {
  25. cin >> a[i];
  26. }
  27. for (int I = 0; I < q; I++) {
  28. cin >> l >> r;
  29. l--;
  30. r--;
  31. ans = 0;
  32. for (int ln = 1; ln <= (r - l + 1); ln++) {
  33. ans += ln * (r - l + 2 - ln);
  34. }
  35. for (int i = l; i <= r; i++) {
  36. for (int j = i; j <= r; j++) {
  37. if (a[i] == a[j]) {
  38. ans -= (r - j + 1);
  39. //t_ans += (r - j + 1);
  40. //cout << j << "->";
  41. }
  42. }
  43. //cout << t_ans << " ";
  44. }
  45. cout << ans << "\n";
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement