Advertisement
deadwing97

PAIRSUM2

Sep 28th, 2019
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using namespace std;
  5.  
  6. int T , n , QN;
  7. int B[1<<20];
  8. long long S[1<<20];
  9. int main(){
  10.  
  11.     cin>>T;
  12.     while(T--) {
  13.         cin>>n>>QN;
  14.         int alln = 0;
  15.         int allq = 0;
  16.         for (int j = 1; j < n; j++)
  17.             cin>>B[j];
  18.         for(int j = 1 , c = 1 ; j <= n ; j++ , c*=-1){
  19.             S[j] = c * B[j] + S[j-1];
  20.  
  21.         }
  22.         for(int j = 1 ; j <= QN ; j++){
  23.             int a , b;
  24.             cin>>a>>b;
  25.             if(b > a) swap(a , b);
  26.             if( (b - a)%2 == 0){
  27.                 puts("UNKNOWN");
  28.                 continue;
  29.             }
  30.             if(a % 2) cout<<S[b-1] - S[a-1]<<endl;
  31.             else cout<<-1 * S[b-1] + S[a-1]<<endl;
  32.         }
  33.     }
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement