fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. // This isn't part of my plan.
  5. const int N = 1e5+5, M = 55, mod = 1e9 +7;
  6. int balls[M][N];
  7. void burn() {
  8. int n , q;
  9. cin >> n >> q;
  10.  
  11.  
  12. for(int i = 0,l,r, m ;i < n;i++) {
  13. cin >> l >> r >> m;
  14. balls[m][l]+=1;
  15. balls[m][r+1]-=1;
  16. }
  17. int total[M]={};
  18. for(int i = 1;i < M;i++) {
  19. for(int j = 1;j < N;j++) {
  20. balls[i][j]+=balls[i][j-1];
  21. total[i]+=balls[i][j];
  22. }
  23. }
  24.  
  25. while(q--) {
  26. int p,x,k;
  27. cin >> p >> x >>k;
  28. if(p == 1) { //insert ball x
  29. balls[k][x]++;
  30. total[k]++;
  31. }
  32. else if (p == 2 ) { //remove ball x
  33. if(balls[k][x])
  34. balls[k][x]--,total[k]--;
  35. }
  36. else { // finding probability that
  37. if(total[k])
  38. cout << fixed << setprecision(6) << (balls[k][x]*1.0/total[k]) << '\n';
  39. else cout << -1 << '\n';
  40. }
  41.  
  42. }
  43.  
  44. }
  45.  
  46. signed main() {
  47. ios::sync_with_stdio(false);
  48. cin.tie(nullptr);
  49. #ifndef ONLINE_JUDGE
  50. freopen("input.txt", "r", stdin);
  51. freopen("output.txt", "w", stdout);
  52. #endif
  53. int tt=1;
  54. // cin>>tt;
  55. while(tt--)
  56. burn();
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0.04s 45644KB
stdin
Standard input is empty
stdout
Standard output is empty