博客
关于我
第十一届十月份蓝桥杯省赛 H - 子串分值和:求字符串所有子串的不同字符个数和(思维/线段树)
阅读量:320 次
发布时间:2019-03-04

本文共 1074 字,大约阅读时间需要 3 分钟。

?????????????????????????????

  • ???????last???????????????
  • ????????????c?????????????????
  • ????????i????????????????prev???????(i - prev) * (n - i + 1)?
  • ????????????????
  • ???????????

    ????

  • ????????????last??????????????????????26???26?????????-1?
  • ?????????????????????????????last???
  • ??????????????????i????????????????prev???????(i - prev) * (n - i + 1)?
  • ??????????????????????????
  • ????

    #include 
    using namespace std;int main() { char s[] = "abcdabca"; int n = strlen(s); int last[26] = {-1}; // ???????????? long long ans = 0; for (int i = 0; i < n; ++i) { char c = s[i]; int idx = c - 'a'; if (last[idx] != -1) { // ???? ans += (i - last[idx]) * (n - i + 1); } // ??????? last[idx] = i; } cout << ans << endl; return 0;}

    ????

  • ??????last???????????????????????-1????????
  • ????????????????????c??????idx?
  • ?????????c???last?????????????????????last[idx]???????(i - last[idx]) * (n - i + 1)????ans??
  • ?????????????i???last[idx]?????????
  • ??????????????ans?
  • ???????????O(n)??????????????

    转载地址:http://siqq.baihongyu.com/

    你可能感兴趣的文章
    OA系统选型:选择好的工作流引擎
    查看>>
    OA让企业业务流程管理科学有“据”
    查看>>
    OA项目之会议通知(查询&是否参会&反馈详情)
    查看>>
    OA项目之我的会议(会议排座&送审)
    查看>>
    OA项目之我的会议(查询)
    查看>>
    OA项目之我的审批(会议查询&会议签字)
    查看>>
    OA项目之项目简介&会议发布
    查看>>
    ObjC的复制操作
    查看>>
    Object c将一个double值转换为时间格式
    查看>>
    object detection之Win10配置
    查看>>
    object detection训练自己数据
    查看>>
    object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
    查看>>
    object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
    查看>>
    object detection错误之no module named nets
    查看>>
    Object of type 'ndarray' is not JSON serializable
    查看>>
    Object Oriented Programming in JavaScript
    查看>>
    object references an unsaved transient instance - save the transient instance before flushing
    查看>>
    Object 类的常见方法有哪些?
    查看>>
    Object-c动态特性
    查看>>
    Object.assign用法
    查看>>