Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int xor(int m, int n){
  4. if((m==1 && n==0)||(m==0 && n==1)){
  5. return 1;
  6. }else if((m==1 && n==1)||(m==0 && n==0)){
  7. return 0;
  8. }
  9. }
  10. int main(){
  11. int N,Q;
  12. int lastAnswer = 0;
  13. printf("Enter the values of N and Q respectively : \n");
  14. scanf("%d %d",&N,&Q);
  15. int *p[N];
  16. int i,j=0;
  17. for(i=0;i<N;i++){
  18. p[i] = (int *)malloc(Q*sizeof(int));
  19. }
  20. int q,x,y;
  21. int count[N];
  22. for(i=0;i<N;i++){
  23. count[i] = 0;
  24. }
  25. printf("Enter the next %d lines of input : \n",Q);
  26. for(i=0;i<Q;i++){
  27. scanf("%d %d %d",&q,&x,&y);
  28. if(q==1){
  29. *(p[xor(x,lastAnswer)%N]+count[xor(x,lastAnswer)%N]) = y;
  30. count[xor(x,lastAnswer)%N]++;
  31. }else{
  32. lastAnswer = *(p[xor(x,lastAnswer)%N]+count[y%count[xor(x,lastAnswer)%N]]);
  33. printf("%d\n",lastAnswer);
  34. }
  35. }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement