[ODT] Codeforces 896C. Willem, Chtholly and Seniorious

本文介绍了一种名为ODT的树形数据结构及其应用,该结构使用平衡树来维护区间,并通过暴力修改来更新这些区间。文章提供了一个示例程序,展示了如何使用这种数据结构进行区间加法、区间赋值、查询区间最小值及区间幂运算。

据ODT在CF上说,是一种叫ODT的树

用平衡树维护区间,暴力修改维护这些区间。

因为数据随机,所以跑得快…

发现自己不会用SET………

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <assert.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;

typedef pair<int,int> seg;

map<seg,ll> S;

int n,m,seed,vmax;

inline int ran(){
  int ret=seed;
  seed=(7LL*seed+13)%1000000007;
  return ret;
}

inline int Pow(ll x,ll y,ll P){
  int ret=1; x%=P;
  for(;y;y>>=1,x=x*x%P) if(y&1) ret=x*ret%P;
  return ret;
}

int main(){
  freopen("1.in","r",stdin);
  freopen("1.out","w",stdout);
  scanf("%d%d%d%d",&n,&m,&seed,&vmax);
  for(int i=1;i<=n;i++){
    int cur=ran()%vmax+1;
    S[seg(i,i)]=cur;
  }

  for(int i=1;i<=m;i++){
    int opt=ran()%4+1,l=ran()%n+1,r=ran()%n+1,x,y;
    if(l>r) swap(l,r);
    if(opt==3) x=ran()%(r-l+1)+1;
    else x=ran()%vmax+1;
    if(opt==4) y=ran()%vmax+1;

    if(opt==1){
      map<seg,ll>::iterator IT=S.upper_bound(seg(l-1,1<<30));
      if(IT->fi.fi!=l){
    IT--;
    seg a1=seg(IT->fi.fi,l-1),a2=seg(l,min(r,IT->fi.se)); ll c=IT->se;
    if(IT->fi.se>r){
      seg a3=seg(r+1,IT->fi.se);
      S.erase(IT); S[a1]=c; S[a2]=c+x; S[a3]=c;
    }
    else S.erase(IT),S[a1]=c,S[a2]=c+x;
    IT=S.upper_bound(seg(l,1<<30));
      }
      while(IT!=S.end() && IT->fi.fi<=r){
    if(IT->fi.se<=r) IT->se+=x;
    else{
      int L=IT->fi.fi,R=IT->fi.se; ll v=IT->se;
      S.erase(IT);
      S[seg(L,r)]=v+x; S[seg(r+1,R)]=v;
      break;
    }
    IT++;
      }
    }
    else if(opt==2){
      map<seg,ll>::iterator IT=S.upper_bound(seg(l-1,1<<30));
      if(IT->fi.fi!=l){
    IT--;
    seg a1=seg(IT->fi.fi,l-1),a2=seg(l,min(r,IT->fi.se)); ll c=IT->se;
    if(IT->fi.se>r){
      seg a3=seg(r+1,IT->fi.se);
      S.erase(IT); S[a3]=c;
    }
    else S.erase(IT);
    S[a1]=c;
    IT=S.upper_bound(seg(l,1<<30));
      }
      while(IT!=S.end() && IT->fi.fi<=r){
    if(IT->fi.se<=r) S.erase(IT);
    else{
      int L=r+1,R=IT->fi.se; ll v=IT->se;
      S.erase(IT); S[seg(L,R)]=v; break;
    }
    IT=S.upper_bound(seg(l-1,1<<30));
      }
      S[seg(l,r)]=x;
    }
    else if(opt==3){
      vector<pair<ll,int> > v;
      map<seg,ll>::iterator IT=S.upper_bound(seg(l-1,1<<30));
      if(IT->fi.fi!=l){
    IT--;
    v.pb(mp(IT->se,min(r,IT->fi.se)-l+1));
    IT++;
      }
      while(IT!=S.end() && IT->fi.fi<=r){
    v.pb(mp(IT->se,min(IT->fi.se,r)-IT->fi.fi+1)); IT++;
      }
      sort(v.begin(),v.end());
      for(int j=0;j<v.size();j++){
    if(v[j].se>=x){
      printf("%lld\n",v[j].fi);
      break;
    }
    x-=v[j].se;
      }
    }
    else{
      map<seg,ll>::iterator IT=S.upper_bound(seg(l-1,1<<30));
      int ans=0;
      if(IT->fi.fi!=l){
    IT--;
    ans=(ans+1LL*Pow(IT->se,x,y)*(min(r,IT->fi.se)-l+1))%y;
    IT++;
      }
      while(IT!=S.end() && IT->fi.fi<=r){
    if(IT->fi.se<=r) ans=(ans+1LL*Pow(IT->se,x,y)*(IT->fi.se-IT->fi.fi+1))%y;
    else{
      ans=(ans+1LL*Pow(IT->se,x,y)*(r-IT->fi.fi+1))%y; break;
    }
    IT++;
      }
      printf("%d\n",ans);
    }
    //printf("Case %d:\n",i);
    //printf("%d %d %d %d %d\n",opt,l,r,x,y);
    //for(auto c : S) printf("%d %d %lld\n",c.fi.fi,c.fi.se,c.se);
  }
  return 0;
}
### 使用 Qt 在中标麒麟 Linux 系统上读取 ODT 文件的解决方案 在中标麒麟 Linux 系统中,Qt 并未直接提供解析 ODT 文件的功能。然而,可以通过结合 LibreOffice 的命令行工具 `soffice` 将 ODT 文件转换为纯文本文件,然后使用 Qt 读取和处理该文本文件[^1]。 #### 示例代码:通过 Qt 和 LibreOffice 转换并读取 ODT 文件 以下是一个完整的代码示例,展示如何在中标麒麟 Linux 系统上实现这一功能: ```cpp #include <QCoreApplication> #include <QProcess> #include <QFile> #include <QTextStream> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // 定义输入的ODT文件路径和输出的TXT文件路径 QString odtFilePath = "/path/to/input_file.odt"; QString txtFilePath = "/path/to/output_file.txt"; // 使用LibreOffice将ODT文件转换为TXT文件 QProcess libreOfficeProcess; QStringList arguments; arguments << "--headless" << "--convert-to" << "txt" << odtFilePath << "--outdir" << "/path/to/output_directory"; libreOfficeProcess.start("soffice", arguments); if (!libreOfficeProcess.waitForStarted()) { qDebug() << "Failed to start LibreOffice."; return -1; } if (!libreOfficeProcess.waitForFinished()) { qDebug() << "LibreOffice conversion failed."; return -1; } // 检查转换是否成功 if (!QFile::exists(txtFilePath)) { qDebug() << "Converted TXT file does not exist."; return -1; } // 使用Qt读取生成的TXT文件内容 QFile file(txtFilePath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Failed to open TXT file for reading."; return -1; } QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); qDebug() << line; // 输出每一行到控制台 } file.close(); return 0; } ``` #### 代码说明 - **LibreOffice 转换**:通过调用 `soffice` 命令行工具,将 ODT 文件转换为纯文本文件。参数 `--headless` 表示无界面模式运行,`--convert-to txt` 指定输出格式为文本[^1]。 - **Qt 文件读取**:使用 `QFile` 和 `QTextStream` 类读取生成的文本文件,并逐行输出内容到控制台。 - **错误处理**:对每个关键步骤进行错误检查,确保程序的健壮性。 #### 注意事项 - 确保系统已安装 LibreOffice,并且 `soffice` 命令可用。 - 替换代码中的文件路径 `/path/to/input_file.odt` 和 `/path/to/output_directory` 为实际路径。 - 如果需要进一步处理文本内容,可以扩展代码逻辑,例如解析、搜索或替换特定文本。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值