初赛模拟题

· · 个人记录

阅读程序题

1.

#include<bits/stdc++.h>

using namespace std;

const int N = 1145;

int n, m;
double a[N];

double f(int a, int b){
  if(!b) return 1;
  return 1.0 * f(a, b >> 1) * f(a, b >> 1) * (b & 1 ? a : 1);
}

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for(int i = 1; i <= n; i++) cin >> a[i];
  while(m--){
    short l, r, x;
    cin >> l >> r;
    a[l] *= f(x, r - l + 1);
    a[r + 1] /= f(x, r - l + 1);
  }
  for(int i = 2; i <= n; i++){
    a[i] = a[i - 1] * a[i];
  }
  while(n--) cout << fixed << setprecision(13) << a[n + 1] << ' ';
  return 0;
}

其中输入的 n 和 m 均不超过 1000,a 数组中的元素不超过 10,l\le r\le n,x\le 10。

判断题

2.